Private Sub MSComm1_OnComm()MSComm1.Settings = "9600,N,8,1"FoundIt = False' find USB portComFail = FalseFailErr = FalseFor n = 1 To 16 If MSComm1.PortOpen = True Then MSComm1.PortOpen = False On Error Resume Next MSComm1.CommPort = n On Error Resume Next MSComm1.InputLen = 0 MSComm1.PortOpen = True If MSComm1.CommID > 0 Then For i = 1 To 100 Str = "" Str = MSComm1.Input If InStr(Str, "<") > 0 And InStr(Str, ">") > 0 Then GoTo jump: ' in this case the output from Your Arduino would be "< R >" or "< Y >" of < G > ".... Sleep 50 Next i End IfNext nIf MSComm1.PortOpen = False Then MsgBox "Controller Not functioning , Please check USB connection", vbCritical, "": ComFail = True: Exit Subjump: ' your case statement Debug.Print Str; Select Case (Str) ' set a break point here so you can step through the case statement Case "A" Call LEDOn(vbRed) Case "B" Call LEDOn(vbGreen) Case "C" Call LEDOn(vbBlue) Case "D" Call LEDOn(vbYellow) Case Else Call LEDOffEnd SubPrivate Sub LEDOn(col As Long)End SubShape1.FillColor = colEnd SubPrivate Sub LEDOff()End SubShape1.FillColor = vbWhiteEnd Sub
Private Sub LEDOn(col As Long)End SubShape1.FillColor = colEnd SubPrivate Sub LEDOff()End Sub Shape1.FillColor = vbWhiteEnd Sub
Serial.print("< "); Serial.print(ColorStr); // output to computer USB port Serial.println(">");
strt = InStr(str, "<") + 1 fin = InStr(str, ">") If (fin - strt) <= 0 Then Exit Function Else ColorStr = Mid(str, strt, (fin - strt)) End If
Str = ""
Private Sub LEDOn(col As Long)End SubShape1.FillColor = col //in this code the error appearsEnd SubPrivate Sub LEDOff()End Sub Shape1.FillColor = vbWhiteEnd Sub
learn to set breakpoints and step through the VB code
Private Sub LEDOn(col As Long)End Sub // this is theoretically correct, but makes no senseShape1.FillColor = col //in this code the error appears , because VB was told Sub LEDOn has ended alreadyEnd Sub
1. i can't understand the what does it means..
Dim Str as String