You can use the InputBox function to get a string of text from the user. Here's the syntax for this function:
Public Function InputBox(Prompt As String [, Title As _ String = "" [, DefaultResponse As String = "" [, _ XPos As Integer = -1 [, YPos As Integer = -1]]]]) As String
And here are the arguments for this function:
Prompt— A string expression displayed as the message in the dialog box. The maximum length is about 1,024 characters (depending on the width of the characters used).
Title— String expression displayed in the title bar of the dialog box. Note that if you omit Title, the application name is placed in the title bar.
DefaultResponse— A string expression displayed in the text box as the default response if no other input is provided. Note that if you omit DefaultResponse, the displayed text box is empty.
XPos— The distance in pixels of the left edge of the dialog box from the left edge of the screen. Note that if you omit XPos, the dialog box is centered horizontally.
YPos— The distance in pixels of the upper edge of the dialog box from the top of the screen. Note that if you omit YPos, the dialog box is positioned vertically about one-third of the way down the screen.
Input boxes let you display a prompt and read a line of text typed by the user, and the InputBox function returns the string result. Here's an example from the MsgAndInputBoxes example on the CD-ROM:
Private Sub Button3_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button3.Click Dim Result As String Result = InputBox("Enter your text!") TextBox1.Text = Result End Sub
You can see the results of this code in Figure 4.7.
When the user enters text and clicks OK, the InputBox function returns that text, and the code displays it in the text box in the MsgAndInput example, as you see in Figure 4.8.