public myVar as string
Scope: the page it is declared in. Loses value on postbacks. The public
qualifier does not really imply state at all. What public means is that any
class that references the class that holds myVar has access to that
variable. to illustrate:
Public class MyClass
Public myVar as string = "hello world"
Private myvar2 as string = "good-bye!"
end class
Public class _Default
dim oMyClass as new MyClass
dim test as string = oMyClass.myvar ' this works fine since myVar is public
it is accesible to _Default
dim test2 as string = oMyClass.myvar2 'This will throw an error because
myVar2 is only accessible inside MyClass
end class
to make a variable Global to the whole app you have 2 choices:
1. Session("MyID")
The session object will retain state past postbacks and pages. Session is
user specific (i.e. not shared) So my Session("MyID") will have a completely
different value from your Session("MyID"). You would use this for things
like passing a user id or the contents of a shopping cart throughout the
pages on your site the user accesses
2. Application("CountUsers")
the application object has almost all the same properties as session
however, the application object is available to all users. A good example of
Application("whatever") is at forums that show how many users are currently
signed in. that is to say that Application("CountUsers") will have the same
value for everybody.
There are tons of resources available on line that go into much further
detail if you need
"BB" <an*******@discussions.microsoft.com> wrote in message
news:39**********************************@microsof t.com...
Hello all,
I might be missing something here, but am trying to understand the
difference between using application-level variables--i.e.
Application("MyVar")--and global variables--i.e. public myVar as string,
etc. It seems to me that the scope and duration are the same, as they both
are there while the application is running, and both go away when it quits.
I presume that one difference is that the application state can be
"flushed," such as with on-line changes to global.asax, but any additional
thoughts are appreciated.
Regards,
Bill Borg
Thanks,
Bill Borg