Problem with strings

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello. I am using vb.net.

I have some problem with the data type 'string'.
There is a textbox and a button in my program.
When the button is clicked, the program checks whether the text in the
textbox is "Hello World!" or not. I use the following line of code:

Dim T As String
textbox1.Text() = T
If ((T Is "Hello World!) = True) Then
MsgBox("True")
Else
MsgBox("False")
End If

However, the "True" dialog box never appears, even if I copy "Hello World!"
directly from the source file and paste it to the program.

Could anybody tell me how I can fix this? Thanks in advance.
 
Try this:

Dim T As String
textbox1.Text = T
If (T.Equals("Hello World!"))Then
MsgBox("True")
Else
MsgBox("False")
End If
 
Xero,

You are using strange code see me commenct inline in this message
Dim T As String

With this you make a new string which you do not directly need
textbox1.Text() = T

Here you set the Textbox1.text on spaces because T is an empty string
If ((T Is "Hello World!) = True) Then

What you do here is really not to understand for me, It looks if you try to
check if the object T is the same as the object from "Hello World!" what is
impossible in VBNet because every String has forever its own object
reference (the word used is immutable).

That sentence above can be

If textbox1.Text = "Hello World!" then
MessageBox.Show("True")
'you can use that msgBox as well however this is more the new way
Else
MessageBox.Show("False")
With which in my idea your code should work.

I hope this helps a little bit?

Cor
 
Back
Top