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.

Private Sub BtnHello_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
 Handles BtnHello.Click
   Dim User As String
   User = InputBox("What is your name?", "Greetings")
   Me.Text = "Hello " & User
End Sub 'BtnHello_Click

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

Message Boxes

A message box is similar to an input box. The message box can be used as either a function (returns an answer) or a statement (no answer returned) The programmer can select the type of message box to display. The type indicates which command buttons to display: Yes, No, OK, Cancel, Abort, Retry, etc.

There are two formats for opening a message box: as a statement or as a function that returns an answer.

The format for the statement is:
      msgBox <prompt>,type,<Title>

This method is usually used when the only button on the message box is OK. We do not need to find out which button they pressed, they’re going to press OK!


INDEX, Text Boxes, Input Boxes, Message Boxes, More Message Boxes, Dialog Boxes, Open File Dialog
Next lesson: Loops in Visual Basic

Copyright © Zebra0.com
All rights reserved worldwide.

 
 

Input Boxes