Discussion in "Software" started by    z_jun    Oct 25, 2009.
Sun Oct 25 2009, 01:50 pm
#1
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.
Mon Oct 26 2009, 12:23 am
#2
Does it work if you create "Word" and set it to "O" without using
"Word = StrConv(MSComm1.Input, vbUnicode)"
Mon Oct 26 2009, 12:36 am
#3
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


[ Edited Mon Oct 26 2009, 12:43 am ]
Mon Oct 26 2009, 11:04 am
#4
But I want to use StrConv to display the input obtained correctly...
Mon Oct 26 2009, 06:11 pm
#5
are you sure the case are same?

i mean capital O not small is being sent from hardware.
Mon Oct 26 2009, 08:33 pm
#6
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.

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

Michailqfh
Fri Mar 29 2024, 01:53 am
Bobbyerilar
Thu Mar 28 2024, 08:08 am
pb58
Thu Mar 28 2024, 05:54 am
Clarazkafup
Thu Mar 28 2024, 02:24 am
Walterkic
Thu Mar 28 2024, 01:19 am
Davidusawn
Wed Mar 27 2024, 08:30 pm
Richardsop
Tue Mar 26 2024, 10:33 pm
Stevencog
Tue Mar 26 2024, 04:26 pm