single execution of code at start...help required

Thread Solved

Join Date: Nov 2009
Posts: 46
Reputation: pankaj.garg is an unknown quantity at this point 
Solved Threads: 0
pankaj.garg pankaj.garg is offline Offline
Light Poster

single execution of code at start...help required

 
0
  #1
Nov 23rd, 2009
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....
Last edited by pankaj.garg; Nov 23rd, 2009 at 3:09 pm.
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 1,211
Reputation: vb5prgrmr will become famous soon enough vb5prgrmr will become famous soon enough 
Solved Threads: 220
vb5prgrmr vb5prgrmr is offline Offline
Nearly a Posting Virtuoso
 
0
  #2
Nov 23rd, 2009
In module...
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. 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...
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Option Explicit
  2.  
  3. Public MyValue As Integer
  4.  
  5. Sub Main()
  6. MyValue = 5
  7. Form1.Show
  8. End Sub



Good Luck
If anyone has helped you solve your problem, please mark your thread as solved.

Thanks
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 46
Reputation: pankaj.garg is an unknown quantity at this point 
Solved Threads: 0
pankaj.garg pankaj.garg is offline Offline
Light Poster
 
0
  #3
Nov 24th, 2009
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???


Originally Posted by vb5prgrmr View Post
In module...
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. 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...
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Option Explicit
  2.  
  3. Public MyValue As Integer
  4.  
  5. Sub Main()
  6. MyValue = 5
  7. Form1.Show
  8. End Sub



Good Luck
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 1,211
Reputation: vb5prgrmr will become famous soon enough vb5prgrmr will become famous soon enough 
Solved Threads: 220
vb5prgrmr vb5prgrmr is offline Offline
Nearly a Posting Virtuoso
 
1
  #4
Nov 24th, 2009
Add a module, and add...
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Sub Main()
  2.  
  3. 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
If anyone has helped you solve your problem, please mark your thread as solved.

Thanks
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 611 | Replies: 3
Thread Tools Search this Thread



Tag cloud for Visual Basic 4 / 5 / 6
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC