Click to See Complete Forum and Search --> : Validate real input for a text box control array


Ali Habib
April 16th, 2001, 07:38 AM
I am using a textbox control array and the text boxes should only accept real numbers. I am validating the user input at the lost focus event of the textbox control. The problem is that even when user presses Cancel Button the textbox lostfocus event is call and the validation is done. I don't want the validation to occur when user presses cancel button. How can I achieve this behaviour.
Is there a better event in which I can do the validation, but I must validate the input before user enter another control.
Secondly if I validate the user input in the lost focus event for a textbox control array, the lost focus event keeps on trigering, although it a should triger only once. If I put a break point in the lostfocus event the the behaviour is OK. How can I fix this problem.
Finally when I use the setfocus method of a text box only the cursor moves to that textbox. I want the text to be highlighted also. How can I do that?

I would be greatfull for your help in this regard

Ali.

Joe Keller
April 16th, 2001, 01:08 PM
in response to highlighting the text
use this code for the textbox

Private Sub TextBox_GotFocus()
TextBox.SelStart = 0
TextBox.SelLength = Len(TextBox.Text)
End Sub

Not sure how your application runs.. but couldnt you just validate out the cancel button?

good luck
Joe

forty7
April 16th, 2001, 02:07 PM
Response is in line.

I am using a textbox control array and the text boxes should only accept real numbers. I am validating the user input at the lost focus event of the textbox control.
<Adam> I've found that this is a decent place to place to do validation, but I actually prefer to do it as the user types (change event) if it's possible.

The problem is that even when user presses Cancel Button the textbox lostfocus event is call and the validation is done. I don't want the validation to occur when user presses cancel button. How can I achieve this behaviour.
<Adam> You may want to rethink your response to the invalid data. Do you give a message box to the user that he/she is wrong? Most people don't want another msgbox to click ok on. You might consider changing the back color of the text box to red when it has invalid data, and then only show an error message when the user tries to Save this invalid data. This means that there would not be a msgbox when the user clicks cancel.

Is there a better event in which I can do the validation, but I must validate the input before user enter another control.
<Adam> Do you have to have valid data before they enter the next control, or do you have to let them know if the data is bad? If the program is dependant on valid data before they can move on, you might consider validating on the get focus of each control. Unfortunately, this would require validating all textboxes each time.

Secondly if I validate the user input in the lost focus event for a textbox control array, the lost focus event keeps on trigering, although it a should triger only once. If I put a break point in the lostfocus event the the behaviour is OK. How can I fix this problem.
<Adam> Not sure about this one. I haven't seen this behavior before.

Finally when I use the setfocus method of a text box only the cursor moves to that textbox. I want the text to be highlighted also. How can I do that?
<Adam> You already got a good response on this.


thanx/good luck,
adam