Hey guys, I was wondering if you could provide any tips for the following code I want to write. Basically, I'm building a serial interface with a microcontroller. The interface will read strings from the microcontroller and place the value in the appropriate status box. For example, the microcontroller will send 'A=100' telling me that 100 goes in the 'Amp' textbox. Right now, my code (located below) is capable of sending the right value to the right textbox, but only one string at a time. While values aren't going to be sent constantly, there may be times when the buffer may have more than one string. Say the buffer has "A=100, V=12, P=T, A=121, V=10, ....". How would I read the buffer and separate all the values between the commas? I would then need the separated terms to be put into a new variable for further parsing. I would appreciate any help you guys can provide. Thanks for all the help, this forum has really helped me learn VB on my own!
Xavier
Xavier
Code:
Private Sub AxMSComm1_OnComm(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AxMSComm1.OnComm
Dim a() As String
Dim Temp1, Temp2 As String
Dim String1 As String
If (AxMSComm1.CommEvent = 2) Then
String1 = AxMSComm1.Input 'Save buffer into String1
'Split String1 where '=' is present
a = Microsoft.VisualBasic.Split(String1, "=")
Temp1 = a(0) 'Right side of '='
Temp2 = a(1) 'Left side of '='
If (Temp1 = "A") Then
TextBox1.Text = Temp2 'Send to Amps TextBox
ElseIf (Temp1 = "V") Then
TextBox2.Text = Temp2 'Send to Volts TextBox
ElseIf (Temp1 = "P") Then
If (Temp2 = "T") Then 'If power is on...
'...Put checkmark on Power status box
CheckBox1.CheckState =CheckState.Checked
ElseIf (Temp2 = "F") Then 'If power is off...
'...Remove checkmark from Power status box
CheckBox1.CheckState = CheckState.Unchecked
End If
End If
End If