Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to make subroutine code automatically execute after form loads

Status
Not open for further replies.

dgr7

IS-IT--Management
Dec 29, 2006
43
0
0
US
hello,
I have a VB 6 project where I had some code that I used to execute by clicking a button on the form, and I've 'cut-and-pasted' that code, it's related subroutines it calls, and the form_load coad into a new project.

In this new project, I want the main subroutine which used to be invoked by a button click, I'll call it for now:

Sub CodeToAutomaticallyRunAfterFormLoadCompletes()

to Automatically run as soon as the form_load routine completes and the form is displayed on the screen. I have a Status box in this form that communicates info to use user.
I also need this Sub to not be interruped by anything in it's execution, ie, if the user minimized or switches away focus from the window, and I only need this Sub to run one time...when it's done, the form should close.

How do I setup my project code so that this will happen?

thanks in advance for your help!
david
 
Put the code in a bas module and name it Sub Main, then set your project startup object to be Sub Main

___________________________________________________________
If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
Steam Engine Prints
 
Johnwm,

hello, I tried to do that, but some of the code I put in Main references the status text box on the form, that I send messages to the user through, and when I tried to compile the code, I received an error that sounded like it didn't know how to handle the
status.text = "text here"
commands.

How do I make it so those commands will work from a Module?

fyi, right now I have the code working using a form_activate way of arranging the code.
 
If the status box is on a form then status.text will work if the code is in the same form. But if you switch the code to a module then you have to tell module code which form the status box is on eg Formname.status.text

form_activate will run every time the form is activated (eg if you click on the form while its running it will fire again).

form_load will run once only (unless you unload and reload the form). This is marginally better for your needs.

To close the form
Unload Formname
If this is the only form open the program is finished at that point.

[bigglasses]
 
Well, to have that code in form_activate to run only once, you could use a private module level variable and in the form_activate, run the code if FALSE, and after the code is ran, set it to TRUE (or just use a static variable in form_activate)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top