hddmatrix Posted December 19, 2005 Posted December 19, 2005 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? Quote
Cags Posted December 19, 2005 Posted December 19, 2005 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 "". Quote Anybody looking for a graduate programmer (Midlands, England)?
hddmatrix Posted December 19, 2005 Author Posted December 19, 2005 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 :) Quote
Administrators PlausiblyDamp Posted December 19, 2005 Administrators Posted December 19, 2005 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? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
hddmatrix Posted December 19, 2005 Author Posted December 19, 2005 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 Quote
hddmatrix Posted December 19, 2005 Author Posted December 19, 2005 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......... Quote
Cags Posted December 19, 2005 Posted December 19, 2005 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. Quote Anybody looking for a graduate programmer (Midlands, England)?
hddmatrix Posted December 19, 2005 Author Posted December 19, 2005 Can trim actually remove the vbCrLf in the textbox? I did place that in but no diff..... Quote
Administrators PlausiblyDamp Posted December 19, 2005 Administrators Posted December 19, 2005 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. 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 Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
hddmatrix Posted December 19, 2005 Author Posted December 19, 2005 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. 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: Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.