i have 4-5 forms...all of them are called by each other by some or other procedure...now i want to initialize an variable with an integer value only when my program starts....
my problem is where ever i declare the variable...the form gets called and the variable gets re-initialized...

or

can i declare my integer variable globally and initialize it with a value???

dim globalvariable as integer = 5

gives an error....

i might sound naive...but just hav got stuck on this..

Plz help....

Edited 7 Years Ago by pankaj.garg: n/a

In module...

Public Const MyVar As Integer = 5

However, you will not be able to change this value if you are wanting to have this value change.

Now, there is another way if you have your program start up in a sub main...

Option Explicit

Public MyValue As Integer

Sub Main()
MyValue = 5
Form1.Show
End Sub

Good Luck

Thanks alot...
i cant use the first method..as i need to change the value of variable..

for second method - i havnt used sub main as of now...but seems it will solve my problem...do i need to declare anything else for can i just call my starting form in main()...just like that???

In module...

Public Const MyVar As Integer = 5

However, you will not be able to change this value if you are wanting to have this value change.

Now, there is another way if you have your program start up in a sub main...

Option Explicit

Public MyValue As Integer

Sub Main()
MyValue = 5
Form1.Show
End Sub

Good Luck

Add a module, and add...

Sub Main()

End Sub

Then add the code you need to inside of sub main but don't forget to put in your Form1.Show or your program will look like it does not even run. Next, GoTo Project>Properties and on the right there is a combo box right under the words "Startup Object:". Select Sub Main and hit OK.

Good Luck

Comments
thanks...this helped..
This question has already been answered. Start a new discussion instead.