Compare edittext ?

dibb3386

Member
Licensed User
Longtime User
Hi

Ive been at this for a while and not had much success, so if anyone could help that would be great probably simple as well and ill feel silly afterwards but i cant seem to work it out.

I want to compare the user input text to a word in a file or within the code itself.

User inputs "ghosts" then it'll check the word and if it match's displays correct or something. If its wrong will display a different message.

Ive looked at the CompareTo however cant seem to get it to check the edittext. So could someone please show me an example of how this could work that would be a lot of help.



Thanks for any response with this
 

pluton

Active Member
Licensed User
Longtime User
I will make it much easier for you. I write this from my head so if has mistakes you will corrected it:

In Sub Globals put:
B4X:
Dim EditText1 As EditText
   Dim Word As String
   Dim SomeText As String
   SomeText = "This is some text with few words like ghost, fire, ball, car, fox, jump etc..."

Make one button near EditText and on click event triger this code:
B4X:
Word = EditText1.Text
   If SomeText.Contains(Word) Then
   ToastMessageShow("Yes " &word, False)
   Else
   ToastMessageShow("No", False)
   End If

I think that this will do job
 
Upvote 0

dibb3386

Member
Licensed User
Longtime User
Thanks for the replys, I used what you put pluton .However when i put "ghost" it works fine but also when i use "host" or "ost" it thinks thats correct also. How would i make it so it has to be exact and not just contain part of the words?
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
Here's an alternative which will only match exact words..

B4X:
Dim MyList as List
MyList.Initialize
MyList.AddAll(Array As String("ghost", "fire", "ball", "car")) 

Dim MyWord as String
MyWord=EditText1.Text

If MyList.IndexOf(MyWord)=-1 Then
   ' the word was NOT found in the List
Else
   ' the word WAS found in the List
End If

Martin.
 
Upvote 0

DouglasNYoung

Active Member
Licensed User
Longtime User
A variant of Pluton's solution may also be useful -

Change the word list so that the words are delimited by a specific character, ideally something not likely to be used in the input box - something like

SomeText = ";ghost;fire;ball;car;fox;jump;etc;"

then in the trigger code change the 'contains' function to

If SomeText.Contains(";" & Word & ";") Then

Hope this helps toward the right solution for you,

Douglas
 
Upvote 0

dibb3386

Member
Licensed User
Longtime User
Thanks for all your replies, i got it working

@DouglasNYoung Thanks that did the trick.

Edit: How would I include that when user presses enter on the keyboard it would check the SomeText?, It appears to only check the SomeText when i repress each button/image.Ive tried the EditText1_EnterPressed however i can only get it to hide the keyboard not check it Ill post what ive got so far.....

B4X:
'Activity module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
   Dim EditText1 As EditText
    Dim Word As String
Dim SomeText As String
Dim SomeText2 As String
Activity.LoadLayout("1")
SomeText = ";ghost;Ghost;ball;"
SomeText2 = ";test;Test;"

End Sub

Sub Activity_Create(FirstTime As Boolean)

End Sub

Sub Activity_Resume

End Sub
Sub ImageView1_Click
EditText1.Visible = True 
Word = EditText1.Text

    If SomeText2.Contains(";" & Word & ";") Then
    ToastMessageShow("Yes " &word, False)
    Else
    ToastMessageShow("No", False)
    End If

End Sub

Sub Button1_Click

Word = EditText1.Text

    If SomeText.Contains(";" & Word & ";") Then
    ToastMessageShow("Yes " &word, False)
    Else
    ToastMessageShow("No", False)
    End If
End Sub

Sub Activity_Pause (UserClosed As Boolean)


End Sub
 
Last edited:
Upvote 0

pluton

Active Member
Licensed User
Longtime User
Did you try with

B4X:
EditText1.ForceDoneButton = True

Then put this:
B4X:
Sub EditText1_EnterPressed
Button1_Click ' or just execute here your button code
End Sub
 
Last edited:
Upvote 0

dibb3386

Member
Licensed User
Longtime User

Yes however using edittext_Enterpressed
Button1_click generates an error

Undeclared variable 'button1_click' is used before it was assigned any value.
Occurred on line: 43
Button1_Click

Also the button (Done on keyboard) is for all of them. So i want several images/buttons whatever and each one contains a different set of accepted inputs to generate a message. But each image/button will have a different accepted word.
 
Upvote 0

pluton

Active Member
Licensed User
Longtime User
What I mean't is just put this property for your edittext1

B4X:
EditText1.ForceDoneButton = True

End then in
B4X:
Sub EditText1_EnterPressed 
'put your code what you want to execute
'comapre strings or some other operations
End Sub

I'didn't understand excatly what are you trying to do with:
So i want several images/buttons whatever and each one contains a different set of accepted inputs to generate a message

So you will have several EditText fileds or just one?
Post more description that we can help you
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…