Chapter 4
Chapter 4
Chapter 4
A function is similar to a normal procedure but the main purpose of the function is to accept a certain input from the user and return a value which is passed on to the main program to finish the execution. There are two types of functions, the built-in functions (or internal functions) and the functions created by the programmers.
In this lesson, we are going to learn two very basic but useful internal functions of Visual basic , i.e. the MsgBox( ) and InputBox ( ) functions.
1. MsgBox ( ) Function
The objective of MsgBox is to produce a pop-up message box and prompt the user to click on a command button before he /she can continues. This format is as follows: yourMsg=MsgBox(Prompt, Style Value, Title)
The first argument, Prompt, will display the message in the message box. The Style Value will determine what type of command buttons appear on the message box, please refer Table 10.1 for types of command button displayed. The Title argument will display the title of the message board. Table 10.1: Named Constant vbOkOnly vbOkCancel vbAbortRetryIgnore vbYesNoCancel vbYesNo vbRetryCancel Style Values Buttons Displayed Ok button Ok and Cancel buttons Abort, Retry and Ignore buttons. Yes, No and Cancel buttons Yes and No buttons Retry and Cancel buttons
Style Value 0 1 2 3 4 5
We can use named constant in place of integers for the second argument to make the programs more readable. In fact, VB6 will automatically shows up a list of names constant where you can select one of them. Table 10.2 shows the values, the corresponding named constant and buttons. Table 10.2 : Return Values Value Named Constant 1 vbOk 2 vbCancel 3 vbAbort 4 vbRetry 5 vbIgnore 6 vbYes 7 vbNo and Command Buttons Button Clicked Ok button Cancel button Abort button Retry button Ignore button Yes button No button