User Tools

Site Tools


k16:k16.11:start

16.11 InputBox

The class InputBox (gb. form) implements a simple input dialog box. The class is static and can be used like a function. Therefore, do not search for this component in the IDE!

16.11.1 Call InputBox

The call of the following function opens an input dialog box:

Static Function InputBox (Prompt As String [, Title As String, Default As String] ) As String 
  • Prompt: Text above the text field in which the user enters his text. Note that prompt is a rich text string. This allows for selected text formatting.
  • Title (optional): Title of the dialog.
  • Default (optional): Default text in the text field.

The function returns as a function value the text (data type String) that the user enters or NULL if the user cancels the dialog. The InputBox is less suitable for entering passwords, as the text in the input field cannot be replaced by asterisks or similar for each character.

16.11.2 Example Insert InputBox

The InputBox is a suitable component for interactive user guidance if only one value is to be read in the program flow. This input must then be checked in an appropriate manner so that only valid data can be processed further.

InputBox

Figure 16.11.2.1: input box

The source code is simple - but implements all possible options for the parameters of the function InputBox(…) and two formatting in the rich text of the string sPrompt:

[1] 
[2] Public sOrt As String
[3][4] ..
[5] Public Sub SetLocation() 
[6]   Dim sPrompt, sTitle, sDefault As String
[7]   
[8]   FMain.Hide ' Option
[9]     sPrompt = "Geben Sie den <b><font color='blue'>Bestimmungsort</font></b> ein!"
[10]     sTitle = "Angabe Bestimmungsort ( Deutschland )"
[11]     sDefault = "Osterburg"
[12]     
[13]     sOrt = InputBox(sPrompt, sTitle, sDefault)
[14]   
[15]     If sOrt = Null Then Message.Info("No location has been entered!")
[16]   FMain.Show ' Option
[17]   
[18] End ' SetLocation

If you want to force a city entry, replace line 15:

If sOrt = Null Then 
   Message.Info("No location has been entered!")
   SetLocation() ' Recursive call
Endif ' sOrt = Null ?  

The location entered must then be checked syntactically to prevent nonsensical entries; → 19.6.5 Checking the syntax of character strings.

Download

Articles

Download

The website uses a temporary session cookie. This technically necessary cookie is deleted when the browser is closed. You can find information on cookies in our privacy policy.
k16/k16.11/start.txt · Last modified: 29.09.2023 by emma

Page Tools