UCM
Centurion
Ok guys, here's the scoop...
I open a new blank vb.net project and create 2x forms, each with 1 text box and a button as well as a single module
( I know using modules isn't really the best OOP practice but I'm kinds in a hurry on this project a sin I have less than a couple weeks tobuild and test it... )......
then I add the following code:
form1.vb:
form2.vb:
module1.vb:
and last but not least, I set in project properties, the startup object to: Sub Main
That's it...
My goal here is to create from scratch 2 forms, each running with a single instance and be able to switch from one to the other...
The odd thing is that whenever I run this program, form1 appears for an instant and then the program closes as though it's ended normally...
The only explaination I have for this is that it is possbile that the program runs the code in sub main and then stops execution as though the program has no more code to run...
I suppose 1 solution is to put all of my module code into a form3 and set form3 to be the startup object...The thing is that when I try that, then I'm back to the ol 'nullInstance' issue...
Any ideas?
I open a new blank vb.net project and create 2x forms, each with 1 text box and a button as well as a single module
( I know using modules isn't really the best OOP practice but I'm kinds in a hurry on this project a sin I have less than a couple weeks tobuild and test it... )......
then I add the following code:
form1.vb:
Visual Basic:
Public Class Form1
Inherits System.Windows.Forms.Form
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
AccessMultipleFormsInCodeWITHaModule.switchFormForm1ToForm2()
End Sub
End Class
form2.vb:
Visual Basic:
Public Class Form2
Inherits System.Windows.Forms.Form
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
AccessMultipleFormsInCodeWITHaModule.switchFormForm2ToForm1()
End Sub
End Class
module1.vb:
Visual Basic:
Module Module1
Private myForm1 As New Form1()
Private myForm2 As New Form2()
Public Sub Main()
myForm1.Show()
myForm1.Focus()
End Sub
Public Sub switchFormForm1ToForm2()
myForm1.Hide()
myForm2.Show()
End Sub
Public Sub switchFormForm2ToForm1()
myForm2.Hide()
myForm1.Show()
End Sub
End Module
and last but not least, I set in project properties, the startup object to: Sub Main
That's it...
My goal here is to create from scratch 2 forms, each running with a single instance and be able to switch from one to the other...
The odd thing is that whenever I run this program, form1 appears for an instant and then the program closes as though it's ended normally...
The only explaination I have for this is that it is possbile that the program runs the code in sub main and then stops execution as though the program has no more code to run...
I suppose 1 solution is to put all of my module code into a form3 and set form3 to be the startup object...The thing is that when I try that, then I'm back to the ol 'nullInstance' issue...
Any ideas?
Attachments
Last edited by a moderator: