A friend just asked me how to use serial communication in VB6 or VBA.
So here's just a quick article on how to do this:
If you can't find the MSComm control, just add it this way:
First right click on the toolbar on the right side of the screen in VB:
Then click on: 'components'.
The following screen will appear where you can look for Microsoft Comm Control.
Now you can add this control to your forms.
Here is some code on how to start communication and how to process the recieved data:
startComPort(com_Scale, 1, "9600,e,7,2"))
This function starts the communication with the serial device:
Private Function startComPort(com_obj As MSComm, i_Port As Integer, s_settings As String) As Boolean
On Error GoTo startComPortERROR
com_obj.Settings = s_settings
com_obj.RThreshold = 1
com_obj.SThreshold = 0
com_obj.InputMode = comInputModeText
com_obj.Handshaking = comNone
com_obj.CommPort = i_Port
com_obj.PortOpen = True
startComPort = True
startComPort = False
DBG_ReportError Err.Number, Err.Description, "Weighstation.cls,startComPort", "", True
Then when the serial device gets input this function is fired:
Private Sub com_Scale_OnComm()
On Error GoTo com_OnCommERROR
Dim Text As String
If com_Scale.PortOpen = True Then
Text = com_Scale.Input
If (Err.Number = 8021) And (com_Scale.PortOpen = True) Then
com_Scale.PortOpen = False
DBG_ReportError Err.Number, Err.Description, "Weighstation.cls,com_OnComm", "", True
Special greeting to Gustavo, a brother and colleague in Brazil...