Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Static Variable

Status
Not open for further replies.

Vuzlyn

Programmer
Joined
Jul 13, 2004
Messages
4
Location
US
Is it possible to use a static variable in vbScript when you're using the Microsoft Script Control (in VB)?

Thanks, Vuz
 
What do you mean by static variable?

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Like in VB you can declare a variable using 'Static' and it's basically like declaring it public except it's only availble to that sub. I need to have a variable that will do this same thing.

Thanks, -Vuz-
 
In VBScript, variable scope is local to the block where it was dimmed. Here is an example:
Code:
Option Explicit

Dim strOuter
strOuter = "Outer"

WScript.Echo strOuter
Inner
WScript.Echo strInner

Sub Inner
	Dim strInner
	strInner = "Inner"
End Sub
This will error out on
WScript.Echo strInner
because strInner is only scoped within the block.

I don't know if this helps, but elaborate more and I will answer what I can. If not, one of the smart people will probably weigh in. [bigsmile]

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
I'm writing a game and each script is a different area. The variables need to beable to be changed from within the script and they must retain their values even when the script isn't being run.

Thanks, *Vuz*
 
So you need state persistence. You can do this by editing the script file from within the script itself, however that is just asking for trouble. I would recommend using an XML to maintain persistent values.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top