How to compare 2 strings?

hddmatrix

Newcomer
Joined
Dec 19, 2005
Messages
6
I have the below codes:

Dim pass As String = TextBox2.Text
'returndata is already a string

If trim(returndata) = "" Then
MsgBox("Wrong ID")
Else
MsgBox("Correct ID")
End If

But the messagebox always comes out with "Correct ID", even when the if statement is true.

Anyone here can help?
 
hddmatrix said:
I have the below codes:

Dim pass As String = TextBox2.Text
'returndata is already a string

If trim(returndata) = "" Then
MsgBox("Wrong ID")
Else
MsgBox("Correct ID")
End If
It seems odd to me that you showed where the string pass comes from but then don't use it, and yet you don't show where the string returndata comes from which is whats supposedly causing your problem. I can see no reason this code would always show "Correct ID".

On a side note you should perhaps consider using String.Empty instead of "".
 
Cags said:
It seems odd to me that you showed where the string pass comes from but then don't use it, and yet you don't show where the string returndata comes from which is whats supposedly causing your problem. I can see no reason this code would always show "Correct ID".

On a side note you should perhaps consider using String.Empty instead of "".

hi there thanks for your reply,

At first i do not know where to start with......because it may become very lengthy and complicated.

hmmm...i guess maybe you are right.....it maybe difficult to understand if i just put those codes above...below is where the returndata came from.

Dim bytes(tcpClient.ReceiveBufferSize) As Byte
networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))
Dim returndata As String = Encoding.ASCII.GetString(bytes, 0, bytes.Length)

Thanks :)
 
If you step through the code in a debugger or print the contents of returndata to the debug window what values does it contain? Does it every contain an empty string?
 
PlausiblyDamp said:
If you step through the code in a debugger or print the contents of returndata to the debug window what values does it contain? Does it every contain an empty string?

hi,

I do not know how to get the debug to show me the ouput of the returndata?

I beginning to think that my returndata is not empty.
Because at my server my returndata has a <<enter>>
does this "enter" actually make it look like not a string.empty?

While myReader.Read
textbox1.text += myReader("") & vbCrLf
End While

textbox1.text = returndata
 
it really looks dumb...
i even tried creating another textbox
textbox3.text = ""
textbox3.text += vbCrLf
and compare textbox1 and textbox3.......still keep on correct Id when it is suppose to be wrong id.........
 
To get the debugger to display information you need to set a breakpoint. Todo this click in the gray bar to the left hand side of the code level with a line that contains the variable returndata, then when the application reaches that line it will stop and if you point at the variable it will tell you its value. Alternatively if you didn't understand that output a Messagebox with returndata just before the If statement and see what it contains.
 
If your string contains a CRLF then it isn't an empty string.

If you want to display debug information then Debug.WriteLine(...) will do that for you.

Also as a personal preference you might want to look at using some of the .Net equivalents to the legacy VB routines i.e.
Visual Basic:
Dim pass As String = TextBox2.Text
'returndata is already a string

If returndata.Trim() = String.Empty Then
MessageBox.Show("Wrong ID")
Else
MessageBox.Show("Correct ID")
End If
 
PlausiblyDamp said:
If your string contains a CRLF then it isn't an empty string.

If you want to display debug information then Debug.WriteLine(...) will do that for you.

Also as a personal preference you might want to look at using some of the .Net equivalents to the legacy VB routines i.e.
Visual Basic:
Dim pass As String = TextBox2.Text
'returndata is already a string

If returndata.Trim() = String.Empty Then
MessageBox.Show("Wrong ID")
Else
MessageBox.Show("Correct ID")
End If

hmm...you mean just code: Debug.WriteLine()? Where should i place it?

ok...if my returndata has a VBCRLF....how should i compare it?
:confused:
 
Back
Top