Wednesday, December 12, 2012

messagebox and inputbox in visual basic


Message Box: Message boxes are perfect when you want to alert the user to something happening in your program. For example, an error has occurred, or a game has just ended. Maybe you want to display a congratulatory note or a question about retrying some action.
Here’s the syntax:       retInt = MsgBox(prompt[, buttons] [, title] [, helpfile, context])
The prompt argument holds the string displayed as the message in the dialog box. (The maximum length of prompt is approximately 1,024 characters.)
The buttons argument specifies what to put into the message box, as specified in Table 4.2. The default value for buttons is 0.
Constant                                Value Description
vbOKOnly                 0          Display OK button only
vbOKCancel              1          Display OK and Cancel buttons
vbAbortRetryIgnore 2          Display Abort, Retry, and Ignore buttons
vbYesNoCancel         3          Display Yes, No, and Cancel buttons
vbYesNo                     4          Display Yes and No buttons
vbRetryCancel          5          Display Retry and Cancel buttons
vbCritical                   16        Display Critical Message icon
vbQuestion                 32        Display Warning Query icon
vbExclamation           48        Display Warning Message icon
vbInformation           64        Display Information Message icon

The title parameter holds the string displayed in the title bar of the dialog box. (If you don_t specify title, the application name is placed in the title bar.)
The helpfile argument is a string that identifies the Help file to use to provide context-sensitive Help for the dialog box.
The context argument is the Help context number assigned to the appropriate Help topic.
The possible return values from MsgBox().
Constant                     ValueDescription
vbOK              1          OK
vbCancel        2          Cancel
vbAbort          3          Abort
vbRetry          4          Retry
vbIgnore         5          Ignore
vbYes              6          Yes
vbNo               7          No
The InputBox() Function: You can use the InputBox() function to get a string of text from the user. Here_s the syntax for this function:
InputBox(prompt[, title] [, default] [, xpos] [, ypos] [, helpfile, context])
The prompt argument is a string displayed as the message in the dialog box.
The title argument is a string displayed in the title bar of the dialog box. (If you don_t specify the
title, the application name is placed in the title bar.)
The default argument is a string displayed in the text box as the default response if no other input is provided.
The xpos argument is a number that specifies (in twips) the horizontal distance of the left edge of
the dialog box from the left edge of the screen.
The ypos argument is a number that specifies (in twips) the vertical distance of the upper edge of
the dialog box from the top of the screen.
The helpfile argument is a string that identifies the Help file to use to provide context-sensitive Help for the dialog box.
The context argument is the Help context number assigned to the appropriate Help topic.
The InputBox() function returns the string the user entered.