Hi JRL,
Thanks for that example. When they enter character max+1, your code does a Tab which moves focus away from the field and no more text can be entered. If there were another text field in that dialog though, the extra text would spill over into the second field... and they'd have to delete it as they were meaning to type that text into the first field.
What I'd prefer in this situation instead of tabbing, is to keep the cursor where it is, at the end of the text they just typed in... and perhaps beep to alert them that their extra input has just been discarded.
I made a slight change to your example so it does this (except the beep), see below...
Code: Select all
Dialog>Dialog1
Caption=Dialog1
Width=200
Height=131
Top=CENTER
Left=CENTER
Button=Ok,70,62,51,25,3
Edit=msEdit1,32,16,121,
EndDialog>Dialog1
Show>dialog1
Label>Loop
GetDialogAction>dialog1,res1
If>res1=2,EOF
If>res1=3,Process
Length>%dialog1.msedit1%,stringlength
If>Stringlength>4
MidStr>%dialog1.msedit1%,1,4,dialog1.msedit1
ResetDialogAction>dialog1
//Press tab
Press End
endIf
Wait>0.01
Goto>Loop
SRT>Process
MDL>%dialog1.msedit1%
ResetDialogAction>dialog1
END>Process
Label>EOF
...the only problem is, its not rock solid. To see how it breaks, run the macro and type text into the field very quickly, a bunch of keys all at once and keep going. Periodically, you will see the first character of the already entered text change. Because of timing issues, a character sometimes gets accepted before the "press End" can reposition the cursor to the end... at least it does here on my PC.
So although we can code a fairly workable (but not rock solid) way around this... I still think formally adding a "max length" parameter would be a valid enhancement and hope its on Marcus' wish list.
Along with that idea, a nice-to-have would be the ability to specify an "input mask" for data validation on a per field basis, either validated as each char is typed or when the user tries to switch focus away from the field. Or even the ability to specify a regex patten to validate the field data against. VBScript has a regex engine built in so maybe that could be utilized/called instead of duplicating a regex engine as a Macro Script function.
Thanks and take care...