T
thomasc
This is regarding VB.NET2003.
I wrote a code that works as follows:
1. Form1 loads as program begins
2. By clicking Button1 on Form1, Form2 appears overlapping Form1
3. By clicking Button2 on Form2, Form2 disappears and Form3 appears
overlapping Form1
4. By clicking Button3 on Form3, Form3 disappears and Form4 appears
overlapping Form1
5. By clicking Button4 on Form4, Form4 disappears leaving Form1 only
6. Repeat 2-5
I used the 4 lines of code below to create and load a new form and
close the current form, and it worked fine.
Dim LoadForm As New Form2
LoadForm.Show()
Me.Close()
Me.Dispose()
After I checked my code worked fine, I placed MSComm_OnComm event for
Form2 and Form3,
instead of Button_Click event in order to load a new form and close
current form.
In othere words, I changed it such that any serial input from MSComm
ports on Form2 & Form3
loads a new form and closes the current form.
Unfortunately, an error message pops up while the program processes
from Form3 to Form4.
It reads something like
"An exception of type 'System.NullReferenceException' occured at
'system.windows.forms.dll'.
Additional Information: Object reference has not been set to an
instance of object"
Below is the code I am working on.
The error message pops up right after the procedure "Private Sub
AxMSComm3_OnComm" on Form3 finishes.
Please take a look and let me know what I am doing wrong.
Thank you very much in advance.
Please help!
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
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
Dim LoadForm As New Form2
LoadForm.Show()
End Sub
End Class
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Class Form2
Inherits System.Windows.Forms.Form
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles MyBase.Load
'AxMSComm2.CommPort=3, RThreshold=1, Settings=9600,n,8,1
AxMSComm2.InputLen() = 0
AxMSComm2.PortOpen = True
AxMSComm2.InBufferCount = 0
End Sub
Private Sub AxMSComm2_OnComm(ByVal sender As System.Object, ByVal
e As _
System.EventArgs) Handles AxMSComm2.OnComm
Dim LoadForm As New Form3
LoadForm.Show()
AxMSComm2.PortOpen = False
Me.Close()
Me.Dispose()
End Sub
End Class
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Class Form3
Inherits System.Windows.Forms.Form
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles MyBase.Load
'AxMSComm3.CommPort=1, RThreshold=1, Settings=115200,n,8,1
AxMSComm3.InputLen() = 0 'read the entire buffer when Input is
used
AxMSComm3.PortOpen = True
AxMSComm3.InBufferCount = 0 'clear the receive buffer
End Sub
Private Sub AxMSComm3_OnComm(ByVal sender As System.Object, ByVal
e As _
System.EventArgs) Handles AxMSComm3.OnComm
Dim LoadForm As New Form4
LoadForm.Show()
AxMSComm3.PortOpen = False
Me.Close()
Me.Dispose()
End Sub
End Class
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Class Form4
Inherits System.Windows.Forms.Form
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e
As _
System.EventArgs) Handles Button4.Click
Me.Close()
Me.Dispose()
End Sub
End Class
I wrote a code that works as follows:
1. Form1 loads as program begins
2. By clicking Button1 on Form1, Form2 appears overlapping Form1
3. By clicking Button2 on Form2, Form2 disappears and Form3 appears
overlapping Form1
4. By clicking Button3 on Form3, Form3 disappears and Form4 appears
overlapping Form1
5. By clicking Button4 on Form4, Form4 disappears leaving Form1 only
6. Repeat 2-5
I used the 4 lines of code below to create and load a new form and
close the current form, and it worked fine.
Dim LoadForm As New Form2
LoadForm.Show()
Me.Close()
Me.Dispose()
After I checked my code worked fine, I placed MSComm_OnComm event for
Form2 and Form3,
instead of Button_Click event in order to load a new form and close
current form.
In othere words, I changed it such that any serial input from MSComm
ports on Form2 & Form3
loads a new form and closes the current form.
Unfortunately, an error message pops up while the program processes
from Form3 to Form4.
It reads something like
"An exception of type 'System.NullReferenceException' occured at
'system.windows.forms.dll'.
Additional Information: Object reference has not been set to an
instance of object"
Below is the code I am working on.
The error message pops up right after the procedure "Private Sub
AxMSComm3_OnComm" on Form3 finishes.
Please take a look and let me know what I am doing wrong.
Thank you very much in advance.
Please help!
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
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
Dim LoadForm As New Form2
LoadForm.Show()
End Sub
End Class
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Class Form2
Inherits System.Windows.Forms.Form
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles MyBase.Load
'AxMSComm2.CommPort=3, RThreshold=1, Settings=9600,n,8,1
AxMSComm2.InputLen() = 0
AxMSComm2.PortOpen = True
AxMSComm2.InBufferCount = 0
End Sub
Private Sub AxMSComm2_OnComm(ByVal sender As System.Object, ByVal
e As _
System.EventArgs) Handles AxMSComm2.OnComm
Dim LoadForm As New Form3
LoadForm.Show()
AxMSComm2.PortOpen = False
Me.Close()
Me.Dispose()
End Sub
End Class
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Class Form3
Inherits System.Windows.Forms.Form
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles MyBase.Load
'AxMSComm3.CommPort=1, RThreshold=1, Settings=115200,n,8,1
AxMSComm3.InputLen() = 0 'read the entire buffer when Input is
used
AxMSComm3.PortOpen = True
AxMSComm3.InBufferCount = 0 'clear the receive buffer
End Sub
Private Sub AxMSComm3_OnComm(ByVal sender As System.Object, ByVal
e As _
System.EventArgs) Handles AxMSComm3.OnComm
Dim LoadForm As New Form4
LoadForm.Show()
AxMSComm3.PortOpen = False
Me.Close()
Me.Dispose()
End Sub
End Class
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Class Form4
Inherits System.Windows.Forms.Form
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e
As _
System.EventArgs) Handles Button4.Click
Me.Close()
Me.Dispose()
End Sub
End Class