GNVQ Intermediate IT Optional Unit5

Tutors Sue Cahill and Colin Duley



GNVQ IT Intermediate - Visual Basic Notes 4

Communicating with the user

MESSAGE BOXES

In the programs that you have written so far, you have used Text and Label boxes when you wanted to give the user an instruction or information (“Please enter your name”) or if you wanted the user to type in some data (e.g. the speed of the rocket).

Input boxes and message boxes provide another way of doing this.

To use a message box to send a message to the user we use it as a statement.  It takes the general form: -

where both the message and title are strings, (they can be straight text in quote marks or string variables or functions or combinations of these)

In the following example the title field is omitted

The typecode is a number that is formed by adding together the codes that control which buttons are to appear, which symbol is to be displayed and which button is to be highlighted when the box opens.
 
Button Codes Symbols
OK 0 None
1 OK and Cancel 16
2 Abort, Retry and Ignore 32
3 Yes, No and Cancel 48
4 Yes and No   64
5 Retry and Cancel

Default Button

Where MsgBox is only being used for output, the buttons are not necessary, so the only valid typecodes are 0, 16, 32, 48, 64.

If you don’t want to display a symbol, then the typecode can be omitted altogether

If you want to use a message box to collect a reply, then it must be used as a function.  It takes the general format The value returned by the function will tell us which button was clicked.
 
Value  Button Value  Button
1 OK 2 Cancel
3 Abort 4 Retry
5 Ignore 6 Yes
7 No

INPUT BOXES

An input box is always used as a function

There is no typecode, an input box will always display OK and Cancel and does not hold symbols.  The default value is a string that can be displayed in the entry slot of the box and will be returned if the user presses OK.

 Top of Page
Home Page 
Query for Tutor?