global constant

Chinavo

Member
Joined
Jul 16, 2008
Messages
16
Programming Experience
1-3
Hi

I'm new to vb.net.

I have diffrent forms in my program.

Now i would like to define some variables that can be used by all
of the forms (like directory paths and so on). furthermore i will might
have some functions that also shoud be used by all of the forms.

i searched in diffrent sources but i couldnt fine anything.
I read something about enum but i didnt get it.

do i have to use a class or module?? and how can i use them
in the form classes then?? do i always have to create an intance
of the class??

thanx for the help!

chinavo
 
You can add a module to your project and define public functions within the module that can be called by any form:

you can also instantiate global variables in modules:

VB.NET:
Module basGlobals

Public gstrCCId As String

Public Function MyFunction

End Function

End Module

In this case you would refer to the variable gstrCCId in your form just like you would a local variable. You would also call the function just like you would call a local function.
 
but my.settings is just for global varibles??

for global functions i have to use a module right??
Is a module the best way to do that?'

thanx.

chinavo
 
Yes, a module is the best way, although you can also declare global variables inside your main form.
VB.NET:
Imports System.Text.RegularExpressions
Imports System.Net
Public NotInheritable Class mainform
Public Shared MyName As String

Then, all your other forms can do:

VB.NET:
MainForm.DoThis(1,2,3)
Msgbox(MainForm.MyName)
 
Back
Top