Dialogs in Visual Basic

The user could overlook a text box: if you really want the user's attention, use an input box. The input box pops up and stays open until the user selects OK or Cancel or presses ENTER.
  1. Start a new Windows application named Greetings2.
  2. Add one button named BtnPress with text "Hello".

The statement to open an input box is:

<var>=InputBox(<prompt>,<title>,<default>,<Xpos>,<Ypos>,<HelpFile>,<Context>)
Compare this syntax to the code to display the input box shown below.

'Programmer: Janet Joy
'Format for input box: var=InputBox(prompt,title,default,Xpos,Ypos,HelpFile,Context)
Public Class Form1
    Private Sub BtnPress_Click(sender As Object, e As EventArgs) Handles BtnPress.Click
        Dim User As String
        User = InputBox("What is your name?", "Greetings")
        Me.Text = "Hello " & User
    End Sub
End Class

Of course, the user could still ignore the button, you could put the code to display the input box in form load!

NEXT: Message Boxes