Question 1 serialport 3 forms - currently attempting to use a module in vb 2010 express

jimsee

New member
Joined
Feb 26, 2012
Messages
2
Programming Experience
Beginner
Hello, I ‘m a beginner and have a project that I’m using to turn lights on and off.
I need to use separate forms for display on remote monitors. My problem is each form needs the same serial port open to work and the port won’t open unless it’s closed in the previous form. Using a module works for opening and closing the port, but only for one round. If I try to revisit a form I already accessed it doesn’t work.
Thanks for any suggestions.

I call up one of these subs at the beginning of each form
Module port1

Public SerialPort1 AsControl

Public Sub sp1(byval SerialPort1)
If Form2.SerialPort1.IsOpen = TrueThen Form1.SerialPort1.Close()
If Form3.SerialPort1.IsOpen = TrueThen Form3.SerialPort1.Close()
Form1.SerialPort1.Open()
end sub


Public Sub sp2(byval SerialPort1)
If Form1.SerialPort1.IsOpen = TrueThen Form1.SerialPort1.Close()
If Form3.SerialPort1.IsOpen = TrueThen Form3.SerialPort1.Close()
Form2.SerialPort1.Open()
EndSub



Public Sub sp3(byval SerialPort1)
If Form1.SerialPort1.IsOpen = TrueThen Form1.SerialPort1.Close()
If Form2.SerialPort1.IsOpen = TrueThen Form3.SerialPort1.Close()
Form2.SerialPort1.Open()
EndSub
end Module





 
Last edited:
You should be putting all the serial port functionality into a single class and then all the forms can access it there. That way you only need to open the port once, no matter how many forms you have.
 
Back
Top