Edittext contains

thejackster14

New Member
Licensed User
Longtime User
Hi,
I am creating an application that displays a toast message when the two words kick and door are entered into an edittext. I've been trying to work it out but am new to basic4android so help would be great.
So far this is my line of code that gets stuck...


Sub Globals
Dim txtRoom As EditText
Dim Kick, Door As String
Dim Contains As Boolean
End Sub



Sub wake_Click
If txtRoom.Text.Contains (Kick) And (Door) Then
ToastMessageShow("I kicked the door open", True)
Else
ToastMessageShow("I don't think that will work...", True)
End If
End Sub


There's more to it but I don't think that it is neccessary because it works...



Thanks if you have a solution!
 
1. You have declared the two strings Kick and Door, but you've left them empty.
2. Your use of the AND operator is not correct.


Try

Code: Copy
If txtRoom.Contains ("Kick") And txtRoom.Contains ("Door") then...

Or

Code: Copy
Kick="Kick"
Door="Door"
If txtRoom.Contains (Kick) And txtRoom.Contains (Door) then...
 
Last edited:
Upvote 0
Thanks,
I tried both however I followed them both and didn't manage to get past the debugging step. However adding .Text before .Contains managed to get it into the app up to the step until it paused on the line again.

It says:
Program paused on line: 33
If txtRoom.Text.Contains("Kick") And txtRoom.Text.Contains("Door") Then

Not quite sure if anyone has another answer...?

...Also if I do as you suggested and leave .text out, the debugging window comes up with the following...


Compiling code. Error
Error compiling program.
Error description: Unknown member: contains
Occurred on line: 33
If txtRoom.Contains ("Kick") AND txtRoom.Contains ("Door") Then
Word: contains
 
Upvote 0
Sorry, i thought txtRoom is a string, but it is an edittext.

Code: Copy
If txtRoom.Text.Contains ("Kick") And txtRoom.Text.Contains ("Door") then...
Or

Code: Copy
Kick="Kick"
Door="Door"
If txtRoom.Text.Contains (Kick) And txtRoom.Text.Contains (Door) then...

If you get an error anyway, you may have forgotten:

Code: Copy
TxtRoom.Initialize(...)
Activity.AddView(txtRoom...)

PS. You're posting in the wrong forum, this thread needs to be moved...
 
Upvote 0
Back
Top