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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

textbox validation 2

Status
Not open for further replies.

fishman13

Programmer
Jul 8, 2002
73
US
I have a textbox that can only receive an "A", "B" or "P" value with the MaxLen set to 1. I am trying to place the code to validate the input and send a message, but cannot get everything to work together. I tried in the valid event which triggered the error message, but when I set the value back to NULL or "" the valid keeps getting triggered. I also tried the interactive change and lost focus, but both of these display the error message, but them move on to the next textbox even though they have a setfocus back to the current textbox. Is there some type of input mask that will allow me to only allow those 3 characters and not a blank.
 
why not use a ComboBox who's value are A,B,P 'Entered by Hand' and set it to have a DropDown List?

I think that would be easier than a text box and having all these validations and checking!

No?

Ali Koumaiha
TeknoSoft Inc
Farmington Hills, Michigan
 
I was also thinking of changing to a drop down list, but the textbox valid valid determined the maxlen of other field on the form that I was hopping not to change.
 
The solution to your problem is actually fairly easy. Once you leave the text box and go onto the next control, test the value of the text box here, (in the got focus or click event, etc). Test the value and length of the textbox. If the length or value is wrong, simply set the focus back to the control. You may also want to blank out the text box and/or put a message on the screen.

To test the values, here is a good place to use a case statement. I use these techniques a lot, both to test the value and to auto populate other controls. Saves users a lot of typing.
 
fishman13

Use a textbox, set the format to "!" (no quotes--for all capitals) and set the input mask to "A" (no quotes--only one character) and in the valid event use :
Code:
IF !EMPTY(this.Value)
   IF !INLIST(this.value,"A","B","P")
      this.Value =''
      RETURN .f.  && This will trigger an "invlaid input" wiat window
   ENDIF
endif

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top