Problem in comparing string in VB
Sun Oct 25 2009, 01:50 pm
Hi,
I have encountered a problem when trying to compare strings in Visual Basic.
I have a variable called Word declared as a string. Word is obtained from a SMS read from the phone. Thus, it is assigned this way:
Word = StrConv(MSComm1.Input, vbUnicode)
Then, I have a simple If loop:-
If Word = "O" Then
'go into the loop
However it is not going into the loop even when Word is "O" (I confirmed the contents of Word in the debug mode). I suspect it perhaps has something to do with the vbUnicode? Can someone help me solve this problem? Thanks.
I have encountered a problem when trying to compare strings in Visual Basic.
I have a variable called Word declared as a string. Word is obtained from a SMS read from the phone. Thus, it is assigned this way:
Word = StrConv(MSComm1.Input, vbUnicode)
Then, I have a simple If loop:-
If Word = "O" Then
'go into the loop
However it is not going into the loop even when Word is "O" (I confirmed the contents of Word in the debug mode). I suspect it perhaps has something to do with the vbUnicode? Can someone help me solve this problem? Thanks.
Mon Oct 26 2009, 12:23 am
Does it work if you create "Word" and set it to "O" without using
"Word = StrConv(MSComm1.Input, vbUnicode)"
"Word = StrConv(MSComm1.Input, vbUnicode)"
Mon Oct 26 2009, 12:36 am
I Dont know much about VB but 3 weeks back i completed a project for my friend there
data from land rover is received and i used it as below it worked fine
So my question is what is unicode y should u covert to it anyone plz
Private Sub MSComm1_OnComm()
Dim Data As String
' If comEvReceive Event then get data and display
If MSComm1.CommEvent = comEvReceive Then
Data = MSComm1.Input 'get data
If Data = "L" Then
lblleftsensor.BackColor = vbRed
Timer1.Enabled = True
Else
If Data = "R" Then
lblrightsensor.BackColor = vbRed
Timer2.Enabled = True
Else
If Data = "W" Then
lblwatersensor.BackColor = vbRed
Timer3.Enabled = True
Else
End If
End If
End If
End If
End Sub
data from land rover is received and i used it as below it worked fine
So my question is what is unicode y should u covert to it anyone plz
Private Sub MSComm1_OnComm()
Dim Data As String
' If comEvReceive Event then get data and display
If MSComm1.CommEvent = comEvReceive Then
Data = MSComm1.Input 'get data
If Data = "L" Then
lblleftsensor.BackColor = vbRed
Timer1.Enabled = True
Else
If Data = "R" Then
lblrightsensor.BackColor = vbRed
Timer2.Enabled = True
Else
If Data = "W" Then
lblwatersensor.BackColor = vbRed
Timer3.Enabled = True
Else
End If
End If
End If
End If
End Sub
[ Edited Mon Oct 26 2009, 12:43 am ]
Mon Oct 26 2009, 06:11 pm
are you sure the case are same?
i mean capital O not small is being sent from hardware.
i mean capital O not small is being sent from hardware.
Mon Oct 26 2009, 08:33 pm
Yup...I got a solution already...
Dim a As String
a = Left(StrReverse(Text1.Text), InStr(1, StrReverse(Text1.Text), Chr(34)) - 1)
a = Trim(StrReverse(a))
a = Trim(Left(a, Len(a) - InStr(1, a, vbNewLine) - 1))
a = Replace(a, vbNewLine, "")
a = Left(a, 1)
MsgBox a
'MsgBox Len(a)
If a = "O" Then MsgBox "Enter loop"
Thanks.
Dim a As String
a = Left(StrReverse(Text1.Text), InStr(1, StrReverse(Text1.Text), Chr(34)) - 1)
a = Trim(StrReverse(a))
a = Trim(Left(a, Len(a) - InStr(1, a, vbNewLine) - 1))
a = Replace(a, vbNewLine, "")
a = Left(a, 1)
MsgBox a
'MsgBox Len(a)
If a = "O" Then MsgBox "Enter loop"
Thanks.
Powered by e107 Forum System