RexMundi

Function InputBox options.

3 posts in this topic

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

Share this post


Link to post
Share on other sites



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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now