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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening a form from Sub Main 2

Status
Not open for further replies.

bigfoot

Programmer
May 4, 1999
1,779
0
0
US
I've got a program that I start from a module.

I set the startup object to Sub Main()
When I call the form, it shows the form for a split second and exits the program.

Module1
Dim myForm as new formMain

Sub Main()
myForm.show()

End Sub

If I do it this way, then it works, but I want to call a sub on the form and not the form itself, like myForm.StartMe()
This USED to open the form and run the procedure on the form.

Why can't I keep this program running?
 
Sorry, that should have read:
If I do it this way, --> myForm.ShowDialog() <-- then it works, but I want to call a sub on the form and not the form itself, like myForm.StartMe()

I have another form that I run from the myForm.
 
All these programmers, and no one knows this?

Please..:-(
 
Not quite sure I understand what you're after here. Im assuming you want to create an instance of a form, maybe set some properties of it, and then call it.

Here is what I do.

Create an instance of the new form. Note that any code in the NEW event will fire, which I often use to create any datatables.
Code:
dim f as new frmSimple
'Set any properties
f.iMyId = 12

'Call the Form
f.show()
f.zgo() ' a custom method on the form
f.hide()

ShowDialog will always work as the form is Modal, and the user cannot do anything else until the form is closed. I think you need an application.doevents in your code module





Sweep
...if it works dont mess with it
 
What seems to be happening is if I don't use showmodal, then the program ends. Sub Main runs, shows the form, and ends taking the form with it. So the whole program ends.

Try it and see. It's freaky.

(Thanks, BTW)
 
The behaviour you describe is what I would expect.
Have you tried putting applicateion.doevents as the last line of code in your module



Sweep
...if it works dont mess with it
 
Then what if I need to show another window after that?

Another showdialog, and hide me?
 
Can you please tell me how this is done?

In the meantime, I'll look up Application.Run.
 
JohnYingling,
I had a very similar problem as bigfoot, and your solution worked perfectly. I tried to give you a star, but I'm not sure that process worked as well.

David
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top