-
May 2nd, 2011, 02:07 AM
#1
Thread Starter
Lively Member
[RESOLVED] If Textbox.Text = "" 'Wont Recognize Spaces!
For a text-adventure game I basically have a series of If statements set up to make the game react appropriately based on a series of booleans and other variables as well as what the user has typed into the input text box.
The problem is that I've just realised that VB won't recognize sentences, only words without spaces, dashes, underscore, etc!
To be more clear, my problem is that while this works fine:
vb Code:
If Text1.Text = "North" Then
'Stuff
ElseIf Text1.Text = "South" Then
'Other stuff"
end if
This won't work at all because of the spaces:
vb Code:
If Text1.Text = "Examine the chest" Then
'Stuff
ElseIf Text1.Text = "Open the window" Then
'Other stuff
end if
Does anyone know of some way I can fix this?
I would think there would have to be a way...
-
May 2nd, 2011, 02:22 AM
#2
Lively Member
Re: If Textbox.Text = "" 'Wont Recognize Spaces!
The whole string wrapped in quotes is evaluated and this works,
Code:
If TextBox1.Text = "Examine the chest" Then
MsgBox("Examine the chest is true")
ElseIf TextBox1.Text = "Open the window" Then
MsgBox("Open the window is true")
End If
if you are passing a string variable to a function then use Trim
Code:
Private Sub DoSomething(ByVal str As String)
Dim TheString As String = Trim(str)
Select Case TheString
Case "Examine the chest"
MsgBox(TheString & " is true")
Case "Open the window"
MsgBox(TheString & " is true")
End Select
End Sub
Hope you get it running!
-
May 2nd, 2011, 10:22 PM
#3
Hyperactive Member
Re: [RESOLVED] If Textbox.Text = "" 'Wont Recognize Spaces!
Are the string from the textbox in proper capital like the strings that you are comparing with. Try using .CompareTo() method to eliminate the letter casing differences.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|