Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Please Help!

Hi everyone,

I am new to VB so this might be an easy question but, does anyone know how to wait for a user input to a text box when the form loads?

I need for the text box to have characters in it and then do some further actions but not sure how to wait for the input.

Please help anyone... thanks in advance!
[338 byte] By [karumb2] at [2007-11-11 8:08:15]
# 1 Re: Please Help!
Usually in a Windows application, the app doesn't do anything until the user clicks a button or selects a menu option. So you would display your form with a textbox and allow the user to enter some text, then he or she would click a button to trigger some action. If you set the button's Default property to True, the user can trigger the button by pressing Enter. You may also with to disable the button at design time and enable it in the textbox's Change event only if the textbox contains text.
Phil Weber at 2007-11-11 17:25:55 >
# 2 Re: Please Help!
Is there anyway to perfrom an action without pushing a button, but just based on if there is text in the text box or not? Maybe some type of If statement?
karumb2 at 2007-11-11 17:26:57 >
# 3 Re: Please Help!
There are a number of events that you can code for, including Keypress and Change, that will be triggered if the user types in the text box.
gupex at 2007-11-11 17:27:56 >
# 4 Re: Please Help!
Ahh yes, I think the change event is what I need!

But can you set it so that it only changes on one or two specific values?
karumb2 at 2007-11-11 17:29:01 >
# 5 Re: Please Help!
As its name implies, the Change event fires whenever the text in a textbox changes. There's no way to configure it to behave differently. Instead, put code in the Change event procedure to handle only the text in which you're interested.
Phil Weber at 2007-11-11 17:29:59 >
# 6 Re: Please Help!
I see. Is there anyother suggestions on how to check the string of characters in a textbox without having to press a button? Does Lostfocus or Validate work?
karumb2 at 2007-11-11 17:30:58 >
# 7 Re: Please Help!
Lostfocus or Validate will only occur when another control gets the focus, so that won't help you.

As Phil suggested, use the Change event, combined with if statements, ie. if text1.text = "whatever" then ...,where whatever is the string(s) that you referred to.

Maybe what you are trying to do could be done with a simple button or checkbox?
Lithic at 2007-11-11 17:32:02 >
# 8 Re: Please Help!
I didnt want to use a check box or button, to make the program automated.

I have an RFID reader plugged in that reads to this textbox. Using the change event wont work because it acts as soon as the first character is read in from the scanner, but I need the whole sequence of character to be read in and then perform some actions.

I guess I will try to figure something else out. thanks to all for your help.
karumb2 at 2007-11-11 17:33:02 >
# 9 Re: Please Help!
Are the RFID codes a consistent length? If so, you can use the Len function in the Change event to check the number of characters in the textbox, and kick off your code when the text reaches the desired length.

If the codes are not a consistent length, start a Timer when the first character arrives, then process the text a short time (e.g. 0.5 seconds) later.
Phil Weber at 2007-11-11 17:33:59 >
# 10 Re: Please Help!
IMHO a button is the best choice. so that you let the user to enter the correct string, editing it (that is, deleting retyping etc) and press the button only when the string is correct.
As an alternative you can use the KeyPress or KeyDown events, and take action when the user press Return

Marco
mstraf at 2007-11-11 17:35:00 >