how do i code :-
whether a correct word had been typed into a text box
tink
Printable View
how do i code :-
whether a correct word had been typed into a text box
tink
Do u mean that you want to check whether a user typed in a grammatical valid word?
yes its a specific word that has to be typed in txtbox so i just need how to check if user has typed in correct word.
tink
if lcase(text1) like lcase("yourword") then
Msgbox "you got it right!"
else
msgbox"you got it wrong!"
end if
thanks arc
works a treat , ive got 20 of these txtboxes in all where is the best place to put code , ive put it in the click event but really want all 20 boxes finished before msgbox displays
sorry if this is a stupid question but im still learning
tink
private sub txtbox_KeyUp(Keycode as integer, Shift as integer)
If keycode = vbkeyreturn then
'checkforvalidword
end if
end sub
I'm not i understand exactly what you want, but here is what i would do.
Create a textbox array. This means that you name all of your textboxes the same, such as TxtCheckWord. When you name the second textbox the same as the first one it will ask you if want to create and array. Click yes. After all 20 textboxes are named the same you can proceed with your code.
Now i'm not sure if you are using the textboxes Click event or a buttons click event to check the textboxes, but in a click event put this code.
For i = 0 to 19
if txtCheckWord(i) = "" then
msgbox " you must fill in all the textboxes before you can check them"
exit sub"
next i
You see, now all your textboxes can be checked much easier. Each textbox now has a number next to it. Ranging form 0 to 19. That's the Index number.
the Validate event would be best, then you can cancel the movement to another control if the contents don't fit requirementsQuote:
Originally posted by tink
where is the best place to put code , ive put it in the click event but really want all 20 boxes finished before msgbox displays
sorry if this is a stupid question but im still learning
tink
You guys like to complicate stuff, don't you? :p
Try this:
VB Code:
'When someone presses the button to see if it's right Private Sub cmdSeeIfItsRight_Click() If Text1.Text = "blah blah" And Text2.Text = "blah" And Text3.Text = "yeah" And Text4.Text = "testing" And Text5.Text = "i'm running out of ideas for this thing" Then MsgBox "You got it right!!!" Else MsgBox "WRONG! Try again." End If End Sub
Just add as many textboxes as you need :)
As Chris said, Validate Event:
Code:Private Sub Text1_Validate(Cancel As Boolean)
If StrComp(Text1.Text, "Whatever", vbBinaryCompare) Then
MsgBox "Invalid Data"
Cancel = True: Text1.SetFocus
End If
End Sub