| View previous topic :: View next topic |
| Author |
Message |
compuboy_r
Joined: 04 May 2004 Posts: 68
|
Posted: Tue Jul 20, 2004 4:49 pm Post subject: InputBox |
|
|
How about applying some restrictions to the InputBox command so that one could set the data that can be entered
For example
To input only digits and that too only 6digits in length
there can be more
compuboy_r |
|
| Back to top |
|
 |
BoBo Guest
|
Posted: Wed Jul 21, 2004 8:32 am Post subject: |
|
|
LengthCheck:
StringLen, NumLen, Number
If OutputVar > 6
MsgBox, 4, Validation, Oi ! Max = 6 digits !`nRetry ?
StringValidation:
Interesting !
OutputVar = 123.5
OutputVar /= 1
MsgBox, %OutputVar% ; Returns 123.500000
OutputVar = 123d
OutputVar /= 1
MsgBox, %OutputVar% ; Returns 123 which I think is wrong
OutputVar = abcd
OutputVar /= 1
MsgBox, %OutputVar% ; Returns 0 which could be accepted, Isn't it ?
Well let's change the divisior
OutputVar = 123
OutputVar /= %OutputVar%
MsgBox, %OutputVar% ; Returns 1 that's OK
OutputVar = 123a
OutputVar /= %OutputVar%
MsgBox, %OutputVar% ; Returns 1 which I think is irritating
OutputVar = abcd
OutputVar /= %OutputVar%
MsgBox, %OutputVar% ; AHK Error message - Divide by zero, Well ... |
|
| Back to top |
|
 |
compuboy_r
Joined: 04 May 2004 Posts: 68
|
Posted: Wed Jul 21, 2004 9:30 am Post subject: |
|
|
@Bobo
The method for validation u have told is Post InputBox validation.
But i m thinking of a validation method so that the user wont be able to enter invalid characters in the message box.
compuboy_r |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
Posted: Wed Jul 21, 2004 12:36 pm Post subject: |
|
|
Since InputBox already has a large number of parameters, adding another one that's so rarely use doesn't seem worth the cost in terms of confusion. Plus it's not easy to add parameters to existing commands whose last parameter ("default" in this case) might contain non-escaped commas, since doing so would break existing scripts. But see below for some workarounds.
The easiest workaround is to do an InputBox in a loop and validate the entered string, then break out of the loop when the string is okay. Note that you can use "if var is [not] type" to detect the specific type of a string (numeric, digit, float, etc.).
The most elaborate workaround is to use SetTimer in conjunction with ControlGetText to monitor what the user is typing and use ControlSetText to prevent the typing of unwanted characters or prevent the length of the string from going beyond the maximum. You could even use ToolTip to give the user feedback about mistakes the moment they are made.
Finally, it is only my estimation/opinion that this would be "rarely used". If anyone else thinks this should be added, I'll put it on the list, though since there is a workaround above (untested), it would probably be a low priority. |
|
| Back to top |
|
 |
BoBo Guest
|
Posted: Wed Jul 21, 2004 2:09 pm Post subject: |
|
|
"if var is [not] type" Sorry, haven't found it ... |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
Posted: Wed Jul 21, 2004 2:20 pm Post subject: |
|
|
| Quote: | | "if var is [not] type" Sorry, haven't found it ... |
Here's the link in case you need it: http://www.autohotkey.com/docs/commands/IfIs.htm
| Quote: | OutputVar = 123d
OutputVar /= 1
MsgBox, %OutputVar% ; Returns 123 which I think is wrong
OutputVar = 123a
OutputVar /= %OutputVar%
MsgBox, %OutputVar% ; Returns 1 which I think is irritating |
Strings that start with a number are considered to be that number for math operations. This is done for compatibility with AutoIt v2, and it doesn't seem like a bad convention overall (since "if var is [not] type" is available). |
|
| Back to top |
|
 |
BoBo Guest
|
Posted: Wed Jul 21, 2004 2:40 pm Post subject: |
|
|
| Thanks. |
|
| Back to top |
|
 |
|