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

Displayed form closes automatically

Status
Not open for further replies.

thadley

IS-IT--Management
Aug 19, 2002
5
US
Help,

I am a new to the .net environment and I am hoping to move more into this new world. But, I am struggling with a, I'm sure, a simple problem. When I run the following code.

Module main
'Set DB Connection Info
Public dbServer As String = "tempDB"
Public dbName As String = "namedb"

Sub main()
Dim loginForm As New frmLogin()
loginForm.Show()
End Sub
End Module

This program displays the form for about a second and then it closes. Why?

Thanks so much in advance!
Thom
 
When Sub Main ends, the application ends.

Try this in Sub Main instead of Show.
Application.Run(New frmGen())

but as soon as that form is closed, control will be returned to Sub Main and the application will end regardless if how many other forms are open.

See System.Windows.Forms.Application Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
John,

Thanks very much for the insightful info. That helped.

Sure do appreciate it.

Thom
 
The other thing to do if you want to show the form from sub main is to show it as a dialog.. which stops execution in the calling procedure untill the form is closed.

syntax is as follows

dim myform as form1
myform.showdialog
That'l do donkey, that'l do
[bravo] Mark
 
dim myform as Newform1
myform.showdialog

The problem with ShowDialog (modal form) is that you can not show other forms as modeless and you can not hide the modal form. Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Thanks again for the insight. Here is a thought. Would it be possible to use the .showDialog for the username and password form, check for the correct information, and if it is correct use the Application.Run(New frmGen())
to begin the "real" program? One downside, I guess, is figuring out how to close the dialog window.

Thanks again,
Thom
 
Great idea! That worked. Clean and simple....well simple is relative. I really do appreciate the help and time.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top