accessing variables
-
simple question.. using vb.net for a small vb windows app: where is the best place to declare an object variable? i have a custom structure which i have delcared a variable array with.. each method in the program must be able to access this variable (its a simple 1 form, module, class program) thanx in advance. EDIT: i am currently using a module level variable ------------------ Jordan. III
-
simple question.. using vb.net for a small vb windows app: where is the best place to declare an object variable? i have a custom structure which i have delcared a variable array with.. each method in the program must be able to access this variable (its a simple 1 form, module, class program) thanx in advance. EDIT: i am currently using a module level variable ------------------ Jordan. III
If your variable is going to be accessed by many of the methods in your class, make it a global variable by putting it just after your class statement.
Public Class myForm
Inherits System.Windows.Forms.Form
' Global Variables go here
Private myGlobal as Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
.
.
.RageInTheMachine9532
-
If your variable is going to be accessed by many of the methods in your class, make it a global variable by putting it just after your class statement.
Public Class myForm
Inherits System.Windows.Forms.Form
' Global Variables go here
Private myGlobal as Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
.
.
.RageInTheMachine9532
ok thats how i am doing it. i was just wondering if this was the most efficient way of attacking this. also, i used 'dim' rather than 'private', in classes they are the same thing, no? are they always the same thing? thanks Dave ------------------------ Jordan. III
-
ok thats how i am doing it. i was just wondering if this was the most efficient way of attacking this. also, i used 'dim' rather than 'private', in classes they are the same thing, no? are they always the same thing? thanks Dave ------------------------ Jordan. III
They do the same thing, such that Dim is actually optional. But, the variable visibility changes depending on wether it is declared with Public, Private, Friend, Protected, Protected Friend, Static, Shared, ... Look up 'Dim' in the Visual Studio help for the explanation as to what all of these do, with examples. RageInTheMachine9532