![]() |
Proper Validation of xtpControlEdit (VB6) |
Post Reply ![]() |
Author | |||||
Milkman ![]() Newbie ![]() Joined: 16 September 2005 Status: Offline Points: 11 |
![]() ![]() ![]() ![]() ![]() Posted: 16 September 2005 at 11:06pm |
||||
Most of my applications require that any text entered into an edit box
be checked for consistency. For instance, if the user enters xyz
in an ID# edit box, you wouldn't want your program to use a letter
value when it should use a number value. The typical desired
result would be to discard the incorrectly entered value and restore
the previous contents of the edit box.
Unfortunately, the method in which to do this isn't exactly spelled out in the substandard documentation. Adding insult to injury, there isn't even an editbox worked into ANY of the command bar samples. Below is the required code to implement proper validation of an xtpControlEdit within a command bar. It uses the Tag (they call it the "Paramater") property of the edit control to store the previous contents of the edit box. You'll first need to create an ID number for the editbox. Create this global value in a seperate module where you store your constants.
You then need to construct your command bar.
After the control exists you'll need to put some additional code in the "ControlSelected" (catchs when you press the Enter key) and "Update" (catch the case where you change the text and then just leave the text box without pressing the enter key) Events.
You're probably wondering why the "If Control Is Nothing Then Exit Sub" line at the beginning of each event handler. Well it would appear that these event handlers are sometimes called without a control variable passed to it. Very strange. The example programs choose to use the "On Error Resume Next" command to juse ignore any errors. I don't like this approach because it turns off error checking for the rest of the code in the event handler. A bad thing when you're trying to debug your program. Finally you'll need to add the validation routine. Use something like this.
If you want your program to programmatically update the text in the editbox; make sure to change BOTH the .Text and the .Parameter properties to avoid having the validate routine execute needlessly. Now if I can only figure out how to centre text in the thing, I'll be set. Edited by Milkman |
|||||
![]() |
|||||
apuhjee ![]() Senior Member ![]() ![]() Joined: 02 September 2005 Location: United States Status: Offline Points: 130 |
![]() ![]() ![]() ![]() ![]() |
||||
Excellent post - thanks Milkman, you saved a few hairs on my head!
Cheers ~ jp |
|||||
I like mathematics because it is not human and has nothing particular
to do with this planet or with the whole accidental universe — because, like Spinoza's God, it won't love us in return. |
|||||
![]() |
Post Reply ![]() |
|
Tweet
|
Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |