The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
|
|
Validation of input-controls
Posted: 05 Dec 07 5:27 AM
|
hi, i am rather new to SLX-development, so sorry about my maybe simple question...
i'm having a vb-form with several input fields. in a databased there can be found under which cirumstances which control is enabled and has to be validated / filled.
setting a control enabled on basis of this DB works fine. now my questions are: + i would like to use the "required" attribute of a controle to ensure that data is entered. when will this attribute be parsed by SLX? in mbOK-Button-Event? i have set the controls atribute required to true, but still nothing happens...
+ i would like to ensure that data is entered in correct format - therefor i used the "formatType"-attribute of a controle. If i set a field as "ftInteger" and enter a string, it converts the string to "0" - but if you print the .text-attribute of this controle, the string still is provided, not "0". what else do i have to do to ensure type safety in controls?
thanks for you help! |
|
|
|
Re: Validation of input-controls
Posted: 05 Dec 07 6:21 AM
|
Property "required" work with data forms only. You can validate data of controls in the OnValidate event of form. It's lunch before store data. |
|
|
|
Re: Validation of input-controls
Posted: 05 Dec 07 6:27 AM
|
>You can validate data of controls in the OnValidate event of form
but i have to do it manually there? i liked SLX to do it for me (not the content, just the type of data, e.g. numer is really a number; date is really a date et et) - is this possible? |
|
|
| |
|
Re: Validation of input-controls
Posted: 05 Dec 07 6:32 AM
|
i hoped to hear something different...
anyway, thanks for the fast reply - i will see what i can do, maybe i will have some more questions later |
|
|
|
Re: Validation of input-controls
Posted: 05 Dec 07 4:20 PM
|
This is the sort of thing you need ...
Function AXFormValidate(Sender) AXFormValidate = True
If [validatiion fails] then MsgBox [error details] AXFormValidate = false Exit Function End If
End Function |
|
|
|
Re: Validation of input-controls
Posted: 06 Dec 07 6:30 AM
|
thank you, works fine!
just one question: the ".FormatType" and ".FormatString" - attribute of an TEdit - how does it work? Can I use it to enforce a certain format of input-data (e.g. a number, a date, ...)?
if i have to manually check the data format - what is this attribute good for? |
|
|
|
Re: Validation of input-controls
Posted: 06 Dec 07 10:33 AM
|
The two properties you mentioned are masks - they only dictate how the data is seen, not how the data is entered. You can see an example of this on the account screen, under main phone. If you put your cursor in the status field, you can see the phone number formatted (in the U.S., it look like (555)555-5555). If you click the cursor in the main phone field, the formatting goes away and you can see the actual "data" that's in the field, which should look like 5555555555 (if it is stored in the database correctly).
If you are concerned about making sure the user only enters certain characters into the field, use the OnKeyPress event. Each time the user presses any key in the field, it fires this event. I have used this numerous times to make sure users only enter in numbers. Here's an example from my code of an OnKeyPress event:
Sub YourFieldNameOnKeyPress(Sender, Key) If Not IsNumeric(Chr(Key)) AND Key <> 8 Then Key = 0 End Sub
The function basically says that if the key pressed isn't numeric and isn't the backspace key, then change the keystroke to 0, which means nothing is entered into the field. Works like a charm! |
|
|
| |
|