InputBox: Difference between revisions

From AutoIt Wiki
Jump to navigation Jump to search
 
(5 intermediate revisions by the same user not shown)
Line 3: Line 3:


=Syntax=
=Syntax=
$str = InputBox("title","prompt"[,"default"[,"password char[Option]"[,width[,height[,left,top[,timeout[,hwnd]]]]]])
<syntaxhighlight lang="autoit">
InputBox("title","prompt"[,"default"[,"password char[Option]"[,width[,height[,left,top[,timeout[,hwnd]]]]]])
</syntaxhighlight>


=Parameters=
=Parameters=
Line 22: Line 24:
The title, prompt, and default fields set the title of the box, the user prompt, and the initial value of the user input field respectively.
The title, prompt, and default fields set the title of the box, the user prompt, and the initial value of the user input field respectively.


$str = InputBox("Login","Enter your name:","John Generic")
<syntaxhighlight lang="autoit">
Local $str = InputBox("Login","Enter your name:","John Generic")
</syntaxhighlight>


=Password Character=
=Password Character=
Line 31: Line 35:


  ; Require input no larger than 5 characters in length, replace input with "*"
  ; Require input no larger than 5 characters in length, replace input with "*"
$str = InputBox("Password Check","Please enter your password:","noobs","*M5")
<syntaxhighlight lang="autoit">
Local $str = InputBox("Password Check","Please enter your password:","noobs","*M5")
</syntaxhighlight>


=Width & Height=
=Width & Height=
As mentioned above, width and height must be defined together. The size is determined by pixels with a minimum size of 190x115 and a default size of 250x190 however the box is resizable by the user.
As mentioned above, width and height must be defined together. The size is determined by pixels with a minimum size of 190x115 and a default size of 250x190 however the box is resizable by the user.


$str = InputBox("Size Counts","Resize me!","","",190,115)
<syntaxhighlight lang="autoit">
Local $str = InputBox("Size Counts","Resize me!","","",190,115)
</syntaxhighlight>


=Left & Top=
=Left & Top=
Line 64: Line 72:
</table>
</table>


$str = InputBox("Try It","Do Something!","stuff","",10)
<syntaxhighlight lang="autoit">
MsgBox(0,"Bada Bing",@error & " " & $str)
Local $str = InputBox("Try It","Do Something!","stuff","",10)
 
MsgBox(0,"Bada Bing",@error & " " & $str)
</syntaxhighlight>
[[Category:GUI]]
[[Category:GUI]]

Latest revision as of 09:19, 4 November 2017

InputBox displays a popup box prompting the user to enter a string. Adapted from AutoIt doc.

Syntax

InputBox("title","prompt"[,"default"[,"password char[Option]"[,width[,height[,left,top[,timeout[,hwnd]]]]]])

Parameters

ParamPurpose
titleSets the title of the input box
promptSets the prompt to the user
defaultSets user input field to default text
password charSet the character value to replace input.(Optional)
widthSet the width of the window in pixels. Height must also be set. Default value -1 or "Default".(Optional)
heightSet the height of the window in pixels. Width must also be set. Default value -1 or "Default".(Optional)
leftSet the distance of the window from the left side of the screen in pixels. Top must also be set. Default value -1 or "Default".(Optional)
topSet the distance of the window from the top of the screen in pixels. Left must also be set. Default value -1 or "Default".(Optional)
timeoutSet the number of seconds till close.(Optional)
hwndSet the window handle as the parent.(Optional)

Title, Prompt, & Default

The title, prompt, and default fields set the title of the box, the user prompt, and the initial value of the user input field respectively.

Local $str = InputBox("Login","Enter your name:","John Generic")

Password Character

The password char parameter replaces all inputed characters with the first value. Placing a whitespace in the first character position will cause input to be shown as normal. Subsequent characters are used to restrict and enforce input.

  • Options
    • M = Mandatory entry before continuing
    • n = Only n characters may be entered where n is an integer
; Require input no larger than 5 characters in length, replace input with "*"
Local $str = InputBox("Password Check","Please enter your password:","noobs","*M5")

Width & Height

As mentioned above, width and height must be defined together. The size is determined by pixels with a minimum size of 190x115 and a default size of 250x190 however the box is resizable by the user.

Local $str = InputBox("Size Counts","Resize me!","","",190,115)

Left & Top

Like width and height, left and top must be defined together. The position of the box is measured in pixels from the leftmost position on the screen to the topmost. Thus the upper left hand corner of your screen would be at coordinates (0,0). By default the input box is centered but is also movable by the user.

Local $str = InputBox("Move Me","Move me!","","",-1,-1,0,0) ; top left corner of the screen

Timeout

The timeout parameter acts to close the InputBox after x number of seconds have passed.

Local $str = InputBox("Type Fast","What's 6 x 7?","","",-1,-1,Default,Default,3) ; box will close in 3 seconds

If the InputBox times out before a choice is made a 2 is returned.

Return Values

Success: Returns input string and sets @Error

Failure: Returns empty string and sets @Error

Error CodeReason
0Successful execution
1Cancel button pressed
2Timeout occurred
3InputBox failed to open properly
Local $str = InputBox("Try It","Do Something!","stuff","",10)
MsgBox(0,"Bada Bing",@error & " " & $str)