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!
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
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.
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.
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.
Articles