Difference between revisions of "Dialogs and Message Boxes in VB6"
m |
m (→Message Boxes) |
||
Line 53: | Line 53: | ||
Constants | Constants | ||
− | * vbOKOnly 0 Display OK button only. | + | * vbOKOnly 0 Display OK button only. (default) |
* vbOKCancel 1 Display OK and Cancel buttons. | * vbOKCancel 1 Display OK and Cancel buttons. | ||
* vbAbortRetryIgnore 2 Display Abort, Retry, and Ignore buttons. | * vbAbortRetryIgnore 2 Display Abort, Retry, and Ignore buttons. | ||
Line 59: | Line 59: | ||
* vbYesNo 4 Display Yes and No buttons. | * vbYesNo 4 Display Yes and No buttons. | ||
* vbRetryCancel 5 Display Retry and Cancel buttons. | * vbRetryCancel 5 Display Retry and Cancel buttons. | ||
+ | |||
* vbCritical 16 Display Critical Message icon. | * vbCritical 16 Display Critical Message icon. | ||
* vbQuestion 32 Display Warning Query icon. | * vbQuestion 32 Display Warning Query icon. | ||
* vbExclamation 48 Display Warning Message icon. | * vbExclamation 48 Display Warning Message icon. | ||
* vbInformation 64 Display Information Message icon. | * vbInformation 64 Display Information Message icon. | ||
+ | |||
* vbDefaultButton1 0 First button is default. | * vbDefaultButton1 0 First button is default. | ||
* vbDefaultButton2 256 Second button is default. | * vbDefaultButton2 256 Second button is default. | ||
* vbDefaultButton3 512 Third button is default. | * vbDefaultButton3 512 Third button is default. | ||
* vbDefaultButton4 768 Fourth 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. | * 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. | * 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 | * vbMsgBoxHelpButton 16384 Adds Help button to the message box | ||
* VbMsgBoxSetForeground 65536 Specifies the message box window as the foreground window | * VbMsgBoxSetForeground 65536 Specifies the message box window as the foreground window | ||
Line 74: | Line 78: | ||
* vbMsgBoxRtlReading 1048576 Specifies text should appear as right-to-left reading on Hebrew and Arabic systems | * vbMsgBoxRtlReading 1048576 Specifies text should appear as right-to-left reading on Hebrew and Arabic systems | ||
− | Return Values | + | Return Values |
* Constant Value Description | * Constant Value Description | ||
* vbOK 1 OK | * vbOK 1 OK |
Revision as of 14:15, 11 February 2008
Common Dialog Control
- The FileOpen method calls VBGetOpenFileName, which calls Windows GetOpenFileName.
- The FileSaveAs method calls VBGetSaveFileName, which calls Windows GetSaveFileName.
- The FilePrint method calls VBPrintDlg, which calls Windows PrintDlg.
- The FilePageSetup method calls VBPageSetupDlg, which calls Windows PageSetupDlg.
- The OptionFont method calls VBChooseFont, which calls Windows ChooseFont.
- The OptionColor method calls VBChooseColor, which calls Windows ChooseColor.
Private Sub mnuFileOpen_Click() If edit.DirtyDialog Then edit.FileOpen dropFile.Text = edit.filename SetTextMode edit.TextMode End Sub
After checking that the current file is saved, call the FileOpen method of the XEditor object. FileOpen in turn calls VBGetOpenFileName:
Function FileOpen() As Boolean Dim f As Boolean, sFile As String, fReadOnly As Boolean f = VBGetOpenFileName( _ FileName:=sFile, _ ReadOnly:=fReadOnly, _ Filter:=FilterString, _ Owner:=hWnd) If f And sFile <> sEmpty Then TextMode = Not IsRTF(sFile) LoadFile sFile If fReadOnly Then Locked = True FileOpen = True End If End Function
Pass the result to the LoadFile method.
References
You may install the Common Dialog ActiveX Component - comdlg32.ocx - in the ToolBox or use the CDCOpenSave.cls file*
asterik * - class in S2Album
Message Boxes
The MsgBox Function displays a message in a dialog box, waits for the user to click a button, and returns an Integer indicating which button the user clicked. It can be used to provide information or prompt for a user decision.
Syntax
MsgBox(prompt[, buttons] [, title] [, helpfile, context])
Constants
- vbOKOnly 0 Display OK button only. (default)
- 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 1048576 Specifies text should appear as right-to-left reading on Hebrew and Arabic systems
Return Values
- Constant Value Description
- vbOK 1 OK
- vbCancel 2 Cancel
- vbAbort 3 Abort
- vbRetry 4 Retry
- vbIgnore 5 Ignore
- vbYes 6 Yes
- vbNo 7 No
Display a popup alert with a message and OK button:
MsgBox "Invalid input!"
The OK CANCEL dialog:
iYN = Msg("Click OK to Proceed". vbOkCancel,"Startup Menu")
An Alert with YES, NO, and CANCEL (! graphic):
iYN = MsgBox("Click to Test", vbYesNoCancel + vbExclamation, "Test Message")
Simple exit program confirm
Private Sub Command1_Click() Select Case MsgBox("Do you really wish to quit this program?", vbOKCancel + vbQuestion, "Confirmation") Case vbOK Unload Me End Select End Sub
The Input Box
An InputBox( ) function will display a message box where the user can enter a value or a message in the form of text.
Format:
myMessage=InputBox(Prompt, Title, default_text, x-position, y-position)
- Prompt - The message displayed normally as a question asked.
- Title - The title of the Input Box.
- default-text - The default text that appears in the input field where users can use it as his intended input or he may change to the message he wish to key in.
- x-position and y-position - the position or the coordinate of the input box.
Example
userMsg = InputBox("What is your message?", "Message Entry Form", "Enter your messge here", 500, 700)