RexMundi Posted April 12, 2015 Share Posted April 12, 2015 Hi All, I use an InputBox to set a variable in one of my scripts, but I have some trouble figuring out how to make it return want I need, or if it’s even possible to do it? I need the InputBox to return a number to a variable: $Value = InputBox("Drop Amount.", "Enter the quantity you want to drop.", "", " M2", "200", "140") But, there are a few things I’d like to change from the default output: 1. I only want numbers to be allowed in the input field. (Not letters, blanks or special signs) 2. Only numbers between 1 and 40 should be allowed. 3. And fi I press the [Cancel] button, the return value should not be blank, but 0 (Zero). Is any of this possible when using the InputBox function? Or is there another function I can use for this? The Function Reference in the AutoIt Help file doesn’t seem to clarify this. And just for curiosity, what does the hwnd parameter do? /Peace Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 12, 2015 Moderators Share Posted April 12, 2015 RexMundi,Welcome to the AutoIt forums. You cannot modify the InputBox function directly to do what you want - but you can run the returned value through a number of checks to determine if it meets your requirements:#include <MsgBoxConstants.au3> Global $iFinal While 1 $sRet = InputBox("Drop Amount.", "Enter the quantity you want to drop.", "", " M2", "200", "140") ; Check if Cancel pressed If @error Then $iFinal = 0 ExitLoop EndIf ; Convert input into integer $iRet = Int($sRet) Switch $iRet Case 1 To 40 $iFinal = $iRet ExitLoop EndSwitch WEnd MsgBox($MB_SYSTEMMODAL, "Return", $iFinal)If you want to limit the input to digits only, you will need to use a custom dialog with an input using the $ES_NUMBER style. This thread gives you a good steer - do come back if you need more advice. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
RexMundi Posted April 12, 2015 Author Share Posted April 12, 2015 Thank you Melba23, Yeah, I had a feeling that it wasn't possible to configure the InputBox function to do that, and I needed to do some return value checks instead. I just had to ask, since it would have been a lot easier.. I'll try to look at your code and link. Thanks again for a fast and accurate answer. /Peace Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now