Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Validating a textbox field
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Divers
Thread ID:
00067407
Message ID:
00067489
Vues:
24
>>>Thanks, I've changed the code as follows:
>>>
>>>IF len(alltrim(wires.CUtransit))<>8
>>>=messagebox("Transit Number must be 8 characters [ie. 12347879] !",16,oCUWS.appname)
>>>return 0
>>>else
>>> if right(wires.CUtransit,4)<>"7879"
>>> =messagebox("Transit Number must end with '7879' !",16,oCUWS.appname)
>>> return 0
>>> endif
>>>endif
>>>
>>>My problem now is that the user can't do anything unless the field has 8 characters and the last four characters are "7879". I want the user to have the ability to cancel the transaction without having this field correctly filled in. What do I have to change to make this possible.
>>
>>I still don't understand why you show a message when the string doesn't end with "7879". You could have a 4 char entry field and "fix" the string in the valid code by adding the "7879" suffix.
>>
>>Jim Booth gave the solution for your problem: You should have a cancel button on the form with the Cancel property set to .T. and at the begging of your validation method:
>>
>>IF LASTKEY() = 27 && Escape
>> RETURN .T.
>>ENDIF
>>
>>This will allow the user to press Escape to cancel or... and this is the nice part, click on the Cancel button.
>>
>>BTW, when returning from a validation/when procedure, you can use RETURN .T. or RETURN .F. instead of RETURN 1/RETURN 0. Although it works, these methods are supposed to return a logical and not a numerical value. The code becomes more clear this way.
>>
>>Vlad
>
>
>Vlad, Thanks for the advice. I've decided to go with your suggestion and have the user enter the first four characters in that field and have "7879' added programatically.
>
>However, you have lost me with your advice in using the code the code "if lastkey . . ." Specifically, where does this code go?

In the Valid code (at the begining) for your textbox:

IF LASTKEY() = 27
*-- The last pressed key was Escape
*-- The Cancel button will handle this key.
RETURN .T.
ENDIF
*-- You validation code here.

>And what cancel "property"

Any CommandButton has a property named "Cancel". When you set this property to .T., this button is clicked when you press Esc. Also, when you click with the mouse this button, it's like pressing the Esc key. Ie: The LASTKEY() function will return 27, so, your Valid code will return .T.

You can use the Click event of the button to handle the cancel action in your form.

Vlad

>
>Thanks, AL
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform