All About Message Boxes And Input Boxes
Visual Basic provides two ways of displaying message boxes and input dialog boxes:
using MsgBox() and InputBox(). We’ll cover their syntax in the following subsections.
The MsgBox() Function
You use MsgBox() to display a message to the user and get a return value corresponding to one of the buttons in the message box. Here’s the syntax:
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. The default value for buttons is 0.
constants. 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
vbDefaultButton1 0 First button is default
vbDefaultButton2 256 Second button is default
vbDefaultButton3 512 Third button is default
vbDefaultButton4 768 Fourth button is default
vbApplicationModal 0 Application modal; the user must respond to the message box before continuing work in the current application.
vbSystemModal 4096 System modal; all applications are suspended until the user responds to the message box.
vbMsgBoxHelpButton 16384 Adds Help button to the message box
VbMsgBoxSetForeground 65536 Specifies the message box window as the
foreground window
vbMsgBoxRight 524288 Text is right-aligned
vbMsgBoxRtlReading 1048576Specifies text should appear as right-to-left reading on Hebrew and Arabic systems
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.
MsgBox()
return
values.
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
Visual Basic provides two ways of displaying message boxes and input dialog boxes:
using MsgBox() and InputBox(). We’ll cover their syntax in the following subsections.
The MsgBox() Function
You use MsgBox() to display a message to the user and get a return value corresponding to one of the buttons in the message box. Here’s the syntax:
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. The default value for buttons is 0.
constants. 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
vbDefaultButton1 0 First button is default
vbDefaultButton2 256 Second button is default
vbDefaultButton3 512 Third button is default
vbDefaultButton4 768 Fourth button is default
vbApplicationModal 0 Application modal; the user must respond to the message box before continuing work in the current application.
vbSystemModal 4096 System modal; all applications are suspended until the user responds to the message box.
vbMsgBoxHelpButton 16384 Adds Help button to the message box
VbMsgBoxSetForeground 65536 Specifies the message box window as the
foreground window
vbMsgBoxRight 524288 Text is right-aligned
vbMsgBoxRtlReading 1048576Specifies text should appear as right-to-left reading on Hebrew and Arabic systems
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.
MsgBox()
return
values.
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])
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.
Passing Forms To Procedures
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.
Passing Forms To Procedures
You can pass forms to procedures just as you would any object. Here, we_ve set up a subroutine,
ColorWindowWhite(), to turn the background color of a form to white:
Sub ColorWindowWhite(FormToColor As Form)
End Sub
ColorWindowWhite(), to turn the background color of a form to white:
Sub ColorWindowWhite(FormToColor As Form)
End Sub
In this case, we can simply refer to the form passed to this subroutine by the name we’ve given the passed parameter, FormToColor:
Sub ColorWindowWhite (FormToColor As Form)
FormToColor.BackColor = RGB(255, 255, 255)
End Sub
Sub ColorWindowWhite (FormToColor As Form)
FormToColor.BackColor = RGB(255, 255, 255)
End Sub
Now you can pass a form to the ColorWindowWhite() subroutine easily:
Private Sub Command1_Click()
ColorWindowWhite Me
End Sub
Private Sub Command1_Click()
ColorWindowWhite Me
End Sub
0 comments:
Post a Comment
Dear Visitors All The Tricks And Hacks Posted Here Are Only For Knowledge Purpose.Don't Use These for Illegal Operations.