INPUTBOX$: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
m (Update optional args behavior)
(Add more examples and improved optional parameter behavior documentation)
Line 8: Line 8:


{{PageParameters}}
{{PageParameters}}
* {{Parameter|title$}} is the dialog box title
* {{Parameter|title$}} is an optional dialog box title
* {{Parameter|message$}} is the message or prompt that will is displayed in the dialog box
* {{Parameter|message$}} is an optional message or prompt that will is displayed in the dialog box
* {{Parameter|defaultInput$}} is a string that is displayed in the text box as the default response if no other input is provided
* {{Parameter|defaultInput$}} is an optional string that is displayed in the text box as the default response if no other input is provided




{{PageDescription}}
{{PageDescription}}
* All parameters accept an empty string ('''""''') in which case system defaults are used
* All parameters are optional
* Use {{Parameter|message$}} to specify instructions to the user
* Use {{Parameter|message$}} to specify instructions to the user
* If {{Parameter|defaultInput$}} is an empty string ('''""'''), then a password box is shown, and the input is masked
* If {{Parameter|defaultInput$}} is an empty string ('''""'''), then a password box is shown, and the input is masked
Line 25: Line 25:


{{PageExamples}}
{{PageExamples}}
; Example : Hello, world with common dialogs
; Example 1: Hello, world with common dialogs
{{CodeStart}}
{{CodeStart}}
username$ = {{Cl|_INPUTBOX$}}("Hello App", "Enter your name:", "anonymous")
username$ = {{Cl|_INPUTBOX$}}({{Text|<nowiki>"Hello App"</nowiki>|#FFB100}}, {{Text|<nowiki>"Enter your name:"</nowiki>|#FFB100}}, {{Text|<nowiki>"anonymous"</nowiki>|#FFB100}})
{{Cl|IF}} username$ <> "" {{Cl|THEN}} {{Cl|_MESSAGEBOX}} "Hello App", "Hello " + username$, "info"
 
{{Cl|_MESSAGEBOX}} {{Text|<nowiki>"Hello App"</nowiki>|#FFB100}}, {{Text|<nowiki>"Hello "</nowiki>|#FFB100}} + username$, {{Text|<nowiki>"info"</nowiki>|#FFB100}}
{{CodeEnd}}
 
; Example 2: Checking if the user cancelled the input
{{CodeStart}}
age$ = {{Cl|_TRIM$}}({{Cl|_INPUTBOX$}}(, {{Text|<nowiki>"Enter your age:"</nowiki>|#FFB100}}))
 
{{Cl|IF}} {{Cl|LEN}}(age$) = {{Text|0|#F580B1}} {{Cl|THEN}}
    {{Cl|_MESSAGEBOX}} , {{Text|<nowiki>"Cancelled."</nowiki>|#FFB100}}
{{Cl|ELSE}}
    {{Cl|_MESSAGEBOX}} , {{Text|<nowiki>"Age = "</nowiki>|#FFB100}} + age$
{{Cl|END IF}}
{{CodeEnd}}
 
; Example 3: Getting passwords
{{CodeStart}}
password$ = {{Cl|_INPUTBOX$}}({{Text|<nowiki>"Login"</nowiki>|#FFB100}}, {{Text|<nowiki>"Enter password:"</nowiki>|#FFB100}}, {{Text|<nowiki>""</nowiki>|#FFB100}})
 
{{Cl|IF}} {{Cl|LEN}}(password$) = {{Text|0|#F580B1}} {{Cl|THEN}}
    {{Cl|_MESSAGEBOX}} , {{Text|<nowiki>"Cancelled."</nowiki>|#FFB100}}
{{Cl|ELSE}}
    {{Cl|_MESSAGEBOX}} , {{Text|<nowiki>"You entered = "</nowiki>|#FFB100}} + password$
{{Cl|END IF}}
{{CodeEnd}}
{{CodeEnd}}



Revision as of 02:40, 30 November 2023

The _INPUTBOX$ function displays a prompt in a dialog box, waits for the user to input text or click a button, and returns a string containing the contents of the text box. The returned string is an empty string ("") if the user cancelled.


Syntax

result$ = _INPUTBOX$([title$][, message$][, defaultInput$])


Parameters

  • title$ is an optional dialog box title
  • message$ is an optional message or prompt that will is displayed in the dialog box
  • defaultInput$ is an optional string that is displayed in the text box as the default response if no other input is provided


Description

  • All parameters are optional
  • Use message$ to specify instructions to the user
  • If defaultInput$ is an empty string (""), then a password box is shown, and the input is masked
  • The dialog box automatically becomes a modal window if the application window is visible


Availability

  • QB64-PE v3.4.0 and up


Examples

Example 1
Hello, world with common dialogs
username$ = _INPUTBOX$("Hello App", "Enter your name:", "anonymous")

_MESSAGEBOX "Hello App", "Hello " + username$, "info"
Example 2
Checking if the user cancelled the input
age$ = _TRIM$(_INPUTBOX$(, "Enter your age:"))

IF LEN(age$) = 0 THEN
    _MESSAGEBOX , "Cancelled."
ELSE
    _MESSAGEBOX , "Age = " + age$
END IF
Example 3
Getting passwords
password$ = _INPUTBOX$("Login", "Enter password:", "")

IF LEN(password$) = 0 THEN
    _MESSAGEBOX , "Cancelled."
ELSE
    _MESSAGEBOX , "You entered = " + password$
END IF


See also



Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link