How to display forms in order using MSComm

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
 
C

Cor Ligthert[MVP]

Thomas,

Would it not be better if you sent us a snippet of your code and tell us
where it happens.

If I see this and then people asking me to help, then I think, has the
guy/girl really tried to show us the problem

'AxMSComm3.CommPort=1, RThreshold=1, Settings=115200,n,8,1

Cor
 
T

thomasc

Cor,

Thanks much for your reply.
SInce I didn't know how to send you a snippet,
I sent you an email at "[email protected]" with my code
attached.

Please share a few minutes and take a look at the code.
Thank you very much in advance for your help.


* btw, the line you wrote on your reply
'AxMSComm3.CommPort=1, RThreshold=1, Settings=115200,n,8,1
did you want to tell me somthing about it?

I wrote the line in my code to note the settings I set on the Designer
page.
Let me know if you have any comments. thank you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top