Option Explicit
Dim rdet As String
Dim PortNumber As Integer
Dim vol
Dim amp
Dim ohm#
Dim cut
'//»ØèÁ¡´à¾×èÍ Disconnect//
Private Sub Command2_Click()
If MSComm1.PortOpen = True Then
MSComm1.PortOpen = False
End If
Label13.Caption = ""
Label14.Caption = ""
Label13.BackColor = vbRed
Label14.BackColor = vbRed
End Sub
'//àÁ×èÍâËÅ´¿ÍÃìÁ¢Öé¹ÁÒ àÃÔèÁÃѺ¤èÒ//
Private Sub UserControl_Initialize()
MSComm1.CommPort = 13 ' ¡Ó˹´ Com port
MSComm1.Settings = "9600,N,8,1"
End Sub
'//»ØèÁ àÃÔèÁÃѺ¤èÒ//
Private Sub Command1_Click()
If MSComm1.PortOpen = False Then
MSComm1.PortOpen = True
MSComm1.RThreshold = 1
MSComm1.InputLen = 0
If MSComm1.InBufferCount Then
rdet = MSComm1.Input 'get data
Label13.Caption = Left(rdet, 6)
Label14.Caption = Right(rdet, 7)
Label13.BackColor = vbGreen
Label14.BackColor = vbGreen
End If
End If
End Sub
'//૵¤èÒäÁâ¤Ã«Í¿·ì Communication ¤Í¹â·ÃÅ//
Private Sub MSComm1_OnComm()
' If comEvReceive Event then get data and display
If MSComm1.CommEvent = comEvReceive Then
End If
End Sub
'// à¡çº¤èÒŧµÒÃÒ§Íѵâ¹ÁѵÔ//
Private Sub Label3_Click()
cut = Val(Label3.Caption)
cut = Right(rdet, 8)
ohm = 5 / cut
Label3.Caption = ohm
End Sub
Private Sub UserControl_Terminate() 'Close the COMM port àÁ×èͻԴâ»Ãá¡ÃÁ
If MSComm1.PortOpen = True Then
MSComm1.PortOpen = False
End If
End Sub
hi,
I would get the complete string, by reading the MSCOMM and then test the left most character in the string for the '-' sign.
Does the ADC send a CRLF code at the end of the data,?
ie: 0.0000/0.0000 CRLF [ 0x0d,0x0a]
A simple example.
Code:
Private Sub Form_Load()
Dim test, data As String
If test = InStr(1, data, "-") = 0 Then
'.....
Else
'....
End If
'OR
If Left(data, 1) = "-" Then
'...
Else
'...
End If
End Sub