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

Form disappears after launching it from the Main module

Status
Not open for further replies.

IlyaRabyy

Programmer
Nov 9, 2010
571
US
Colleagues,
Subject line says it (again!) Here's thew code of the Main proc.:
Code:
Module ASCII_Text_Search_Main
Public glDevelop As Boolean = System.Diagnostics.Debugger.IsAttached
Public gsStartDir As String = (System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)).Replace("\bin\Debug", "\")
Public Dim gaFileTypes() As String = New String() {}

'====================================================================================================================================
Public Sub Main()
'====================================================================================================================================
FillExtArray()

frmASCII_Text_Search.Show()
End Sub
'====================================================================================================================================
I run it in Debug (F5). The Form flashes and disappears.
I put a break point in the Load proc (at the End Sub statement):
Code:
Public Class frmASCII_Text_Search
Private Sub cmdExit_Click(sender As Object, e As EventArgs) Handles cmdExit.Click
	  Me.Close()
	End
End Sub

'====================================================================================================================================
Private Sub frmASCII_Text_Search_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'====================================================================================================================================
' Purpose       : Initializes Form and its components.
' Description   : Initializes Search in Dir entry box with Program's Start Dir;
'						Fills out the File Types ListBox;
' Side effects  : Shan't be any.
' Notes         : 1. Application-specific.
'                 2. Complies with .NET Framework ver. 1.1 and higher.
' Author        : Ilya I. Rabyy
' Revisions     : by Ilya on 2022-01-25 – started 1st draft.
'====================================================================================================================================
txtSrcDir.Text = gsStartDir
chkSrcSubDirs.Checked = False

Dim lnExtCnt As Int16 = gaFileTypes.Length() - 1

For iPtr As Int16 = 0 To lnExtCnt
	Me.lstExtensions.Items.Add(gaFileTypes(iPtr))
Next

End Sub 'break point here
End Class
At that break point the form appeared, but both controls (txtSrcDir and lstExtensions) were blank (they shouldn't be), and that "blue circle" kept turning, and turning, and turning... until I went Debug/Stop Debugging to "kill" it.
What am I doing wrong?
Please advise.

Regards,

Ilya
 
If you are using sub main, then exiting sub main ends the program and any open forms, and thus the responsibility is on the programmer to control the lifetime of forms, generally by preventing exit of Sub Main until the program has actually finished ...

So, the two quickest ways of achieving this in this particular instance are:

1 Change frmASCII_Text_Search.Show() to frmASCII_Text_Search.ShowDialog()
2 Change frmASCII_Text_Search.Show() to Application.Run(frmASCII_Text_Search)

My preference is the second, as the first option can cause problems with trying to open additional forms, since we are now showing the form modally
 
Change frmASCII_Text_Search.Show() to Application.Run(frmASCII_Text_Search)" - did that.
It works!
Thank you!


Regards,

Ilya
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top