Set character length limiter on text boxes

Ideas for new features & functions

Moderators: Dorian (MJT support), JRL

Post Reply
addiktion
Newbie
Posts: 9
Joined: Wed Jan 30, 2008 7:32 am

Set character length limiter on text boxes

Post by addiktion » Wed Jan 30, 2008 11:46 am

In the Dialog box designer if you add a text box for input it's possible to put as many values as you want in there.

It'd be nice to at least have a check box when your creating the text box object to be able to specify a length that the user can input into the box. Thus preventing users from trying to break the macro once its compiled.

Its possible to code an error message but if this is possible then you can prevent the whole error message all together ;)

User avatar
JRL
Automation Wizard
Posts: 3501
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Wed Jan 30, 2008 1:50 pm

Although a built in length limit parameter might be nice, its possible to control field length in non-modal dialogs with a little coding.

Here's an example:

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
endIf
Wait>0.01
Goto>Loop

SRT>Process
  MDL>%dialog1.msedit1%
  ResetDialogAction>dialog1
END>Process

Label>EOF

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Wed Jan 30, 2008 5:00 pm

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...
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

User avatar
JRL
Automation Wizard
Posts: 3501
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Jan 31, 2008 11:03 pm

Ok...
Not that I don't think having built in length limit capabilities for dialog objects is a good idea, because I do, but I also like a challenge. I altered the altered script and simply sent an Ascii 8 to the field if the specified length limit is reached. Ascii 8 is a backspace.

Is this "rock solid" or can you break it? It wouldn't fail for me but I didn't try very hard.

I think the input mask idea is a good one also. Won't stop me from thinking about how it could be done with the current software.... :)

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
  Ascii>8
endIf
Wait>0.01
Goto>Loop

SRT>Process
  MDL>%dialog1.msedit1%
  ResetDialogAction>dialog1
END>Process

Label>EOF

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Fri Feb 01, 2008 12:06 am

JRL wrote:Ok...
Not that I don't think having built in length limit capabilities for dialog objects is a good idea, because I do, but I also like a challenge.
You sure do... I thought you might give this a shot. :wink:
JRL wrote:I altered the altered script and simply sent an Ascii 8 to the field if the specified length limit is reached. Ascii 8 is a backspace.

Is this "rock solid" or can you break it? It wouldn't fail for me but I didn't try very hard.
Its better... no amount of manual typing could make it fail here... but it is unsuitable for another reason. Type two chars into the field and then hit CTRL-V, only make sure you have a good long line of text in your Windows Clipboard before you paste. See what happens? Like an accordian, the string on screen grows to much larger than the max then shrinks back down to the max of four... funky.

While it technically does work and is an improvement over the previous version, lots of users cut and paste text from one form to another. I would like to specify the max# of chars per field so that pasting in a long string wouldn't produce this visual effect.

If they type (or paste) more than the max into the field, I'd also like the option to produce an audible beep to alert them that their extra input was discarded. Or (more flexible), modally jump to a subroutine where I could code a beep or popup an alert that tells them in words what just happened, etc.
JRL wrote:I think the input mask idea is a good one also. Won't stop me from thinking about how it could be done with the current software.... :)
I'm counting on it. Actually I thought someone might try some magic with the BlockInput> command. Ahh well, I guess this just can't be made bulletproof with the existing software... or can it?
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

User avatar
JRL
Automation Wizard
Posts: 3501
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Fri Feb 01, 2008 12:51 am

but it is unsuitable for another reason. Type two chars into the field and then hit CTRL-V, only make sure you have a good long line of text in your Windows Clipboard before you paste. See what happens?

Code: Select all

Dialog>Dialog1
   Caption=Dialog1
   Width=200
   Height=131
   Top=CENTER
   Left=CENTER
   Edit=msEdit1,65,16,60,
   Button=Ok,70,62,51,25,3
EndDialog>Dialog1

Show>dialog1

Label>Loop
GetDialogAction>dialog1,res1
If>res1=2,EOF
If>res1=3,Process
Length>%dialog1.msedit1%,stringlength
If>Stringlength>6
  MidStr>%dialog1.msedit1%,1,4,dialog1.msedit1
  ResetDialogAction>dialog1
  Press End
endIf
Wait>0.01
If>Stringlength>4
  //MidStr>%dialog1.msedit1%,1,4,dialog1.msedit1
  //ResetDialogAction>dialog1
  //Press tab
  //Press End
  Ascii>8
endIf
Goto>Loop

SRT>Process
  MDL>%dialog1.msedit1%
  ResetDialogAction>dialog1
END>Process

Label>EOF

User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Post by jpuziano » Fri Feb 01, 2008 1:21 am

Hi JRL,

Getting better... that removes the fairly slow-motion accordion effect... but if I keep on hitting CTRL-V and keep trying to paste in a long line of text... I can still see it flash text past 4 chars before that extra text disappears.

Rock solid would be no extra text flashing... at all... but hey, pretty good workaround for a feature that isn't there. You are a wizard with dialogs, thanks for this and for all the other great examples you post.

Who knows, maybe a bulletproof solution could actually be coded, maybe with some Win 32 API calls or by using BlockInput> or or or... The gauntlet is thrown... can anyone do it? Perhaps Marcus himself?

P.S. Hey Marcus, congratulations on the new addition to the family! :)
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

addiktion
Newbie
Posts: 9
Joined: Wed Jan 30, 2008 7:32 am

Post by addiktion » Fri Feb 01, 2008 10:28 am

I'm glad you see you guys have provided work arounds :P I'll have to give these a shot.

Hopefully Marcus can just put in a nice little length limiter so we won't have to write the extra code. I know he was talking about making small changes to the Dialog Designer in another forum. I understand its not a full blown solution in replacing VBs commands and what not and I'm just glad we have one because personally I always liked having one in the Visual Basic/C++ products etc.

All is well though I'm slowly learning. This program provides extensive help tutorials though thank goodness. :D

I'm more of a web designer/mild web developer then anything.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts