AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

InputBox

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Wish List
View previous topic :: View next topic  
Author Message
compuboy_r



Joined: 04 May 2004
Posts: 68

PostPosted: Tue Jul 20, 2004 4:49 pm    Post subject: InputBox Reply with quote

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
View user's profile Send private message
BoBo
Guest





PostPosted: Wed Jul 21, 2004 8:32 am    Post subject: Reply with quote

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 Shocked

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

PostPosted: Wed Jul 21, 2004 9:30 am    Post subject: Reply with quote

@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
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Wed Jul 21, 2004 12:36 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
BoBo
Guest





PostPosted: Wed Jul 21, 2004 2:09 pm    Post subject: Reply with quote

"if var is [not] type" Embarassed Sorry, haven't found it ...
Back to top
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Wed Jul 21, 2004 2:20 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
BoBo
Guest





PostPosted: Wed Jul 21, 2004 2:40 pm    Post subject: Reply with quote

Thanks.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Wish List All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group