Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

text box input

Status
Not open for further replies.

neoice

Programmer
Feb 15, 2003
110
GB
Hello,

I have a text box where I want the user to input an answer.

Private Sub txtanswer_Change()
if txtanswer.text="hello" then end
End Sub

now the problem is that as soon as you press a key the program would end. I want the program to end when you have typed hello and pressed the enter key.

I got it to work with a command box but I would like it to work by pressing the enter key.

I understand that it has something to do with "txtanswer_change" but I couldn't see an alternitive.

I also got my program to work with an input box, but i really would like to use a text box.

cheers,

neil
 
i would also move you end below rather than after the "then"

Private Sub txtanswer_Validate Event ()
if txtanswer.text="hello" then
end
End Sub

I'mnot sure about the valid event though.
 
sorry, i think this is what you may want

Private Sub Txtanswer_KeyPress(KeyAscii As Integer)
If Txtanswer.Text = "hello" Then
End
End If
End Sub
 
I would use the text box keypress option. If keypress= 13 and if textbox = "hello" then end. 13 is the enter key.

 
Hi again guys,

I haven't had much luck with this.

Private Sub txtanswer_KeyPress(KeyAscii As Integer)
If KeyPress = 13 And txtanswer.text = "hello" Then
End
End If

End Sub

The above statement refuses to work.Does anyone have a list of keypress codes.

I also couldn.t get the "validate" sub to work

Private Sub txtanswer_Validate(Cancel As Boolean)

End Sub
 
Heyup,

After frantically messing with the code I have found a solution:-

Private Sub txtanswer_KeyPress(KeyAscii As Integer)
If txtanswer.Text = "hello" Then
End
End If

End Sub

Just need to put in some error correction now.

Thanks for helping me.

cheers

neil
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top