I want to use an object to start my form in VB but when I use an object, the form open but then closes right after. I'm using a vb class as an object to start the application in my projects properties. The problem I encounter is that as soon as it shows the form, it all closes. Nothing stays open. How can I fix this? Here's my code for the object and the forms:
AppStarter.vb:
Public Class AppStarter
Shared Sub Main()
If System.IO.File.Exists("C:\Mingw\bin\g++.exe") Then
Form1.Show()
Else
ErrorPage.Show()
MsgBox("Test")
End If
End Sub
End Class
Form1:
Public Class Form1
Dim fd As OpenFileDialog = New OpenFileDialog()
Dim fld As FolderBrowserDialog = New FolderBrowserDialog()
Dim strFileName As String
Dim strCompiledFileName As String
Dim strFileDestination As String
Dim strFilePath As String
Dim test As Boolean
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub cmdCompile_Click(sender As Object, e As EventArgs) Handles cmdCompile.Click
If txtCompiledFileName.Text <> "" And strFilePath <> "" And strFileDestination <> "" Then
strCompiledFileName = txtCompiledFileName.Text
Try
Process.Start("cmd", "/c cd " + strFileDestination + " & g++ " + strFilePath + " -o " + strCompiledFileName)
MsgBox("Compiled Successfully!")
ClearVar()
Catch ex As Exception
MsgBox(ex)
ClearVar()
End Try
Else
MsgBox("Missing compiled file name or file path.", MessageBoxIcon.Error)
End If
End Sub
Private Sub cmdChooseFile_Click(sender As Object, e As EventArgs) Handles cmdChooseFile.Click
fd.Title = "Open File Dialog"
fd.InitialDirectory = "C:\"
fd.Filter = "C/C++ Files |*.c; *.cpp"
fd.FilterIndex = 1
fd.RestoreDirectory = True
fd.DereferenceLinks = True
If fd.ShowDialog() = DialogResult.OK Then
strFileName = System.IO.Path.GetFileName(fd.FileName)
strFilePath = fd.FileName
End If
lblChosenFile.Text = strFileName
End Sub
Private Sub cmdFileDestination_Click(sender As Object, e As EventArgs) Handles cmdFileDestination.Click
fld.Description = "Select a folder to extract to:"
fld.ShowNewFolderButton = True
fld.SelectedPath = strFileDestination
fld.RootFolder = System.Environment.SpecialFolder.MyComputer
If fld.ShowDialog() = DialogResult.OK Then
strFileDestination = fld.SelectedPath
lblChosenFolder.Text = strFileDestination
End If
End Sub
Public Sub ClearVar()
txtCompiledFileName.Text = ""
lblChosenFile.Text = "No chosen file"
lblChosenFolder.Text = ""
End Sub
End Class
ErrorPage:
Public Class ErrorPage
Dim webAddress As String = "https://osdn.net/projects/mingw/releases/"
Private Sub ErrorPage_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub cmdYes_Click(sender As Object, e As EventArgs) Handles cmdYes.Click
Process.Start(webAddress)
End Sub
Private Sub cmdNo_Click(sender As Object, e As EventArgs) Handles cmdNo.Click
Form1.Close()
Close()
End Sub
Private Const CP_NOCLOSE_BUTTON As Integer = &H200
Protected Overloads Overrides ReadOnly Property CreateParams() As CreateParams
Get
Dim myCp As CreateParams = MyBase.CreateParams
myCp.ClassStyle = myCp.ClassStyle Or CP_NOCLOSE_BUTTON
Return myCp
End Get
End Property
End Class