The InputBox() Function
In the previous section we discussed about the MsgBox()
function, which displays a message to the users and
gives users a way to respond with the command buttons.
If you need to ask the user a question and need a
quick answer, you can use another function that is
the: InputBox() Function.
The InputBox() function like the MsgBox() function
displays a message, but also allows the user to enter
a value that you program can respond to.
An input box 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. |
Here is the format for the InputBox() function:
strAns = InputBox(prompt[, title]
[, default] [, xpos] [, ypos])
The InputBox() function returns a Variant data type
value that you can always interpret as a string. The
returned value is the user's typed response at the
input box.
- prompt: string expression displayed as the message
in the dialog box.
- title: string expression displayed in the title
bar of the dialog box.
- default: string expression displayed in the
text box as the default response if no other input
is provided.
- xpos, ypos: twip coordinate where you want the
input box to appear in the form window.
The following statement will generate an input box:
strAns = InputBox("What is you
Name?", "Get Name")
The InpoutBox() function returns a zero length string
(""), If the user clicks the Cancel button
instead of entering a value.
If (strAns <> "")
then
Else
End If
VB supports a special value named Empty that you
can use in place of "". The Empty keyword
makes your code cleaner.
|