1 / 16

MsgBox Function

MsgBox Function. Displays one of Visual Basic’s predefined dialog boxes, which contains a message, one or more command buttons, and an icon

barid
Download Presentation

MsgBox Function

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. MsgBox Function • Displays one of Visual Basic’s predefined dialog boxes, which contains a message, one or more command buttons, and an icon • After displaying the dialog box, the MsgBox function waits for the user to choose a button, then returns a value that indicates which button the user selected

  2. MsgBox Function • Syntax: MsgBox(prompt[, buttons][, title][,helpfile, context]) • prompt is the message you want displayed • buttons is a numeric expression that specifies the number and type of buttons, the icon, the default button, and the modality • title is a string expression displayed in the title bar

  3. buttons Argument ConstantValueDescription 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.

  4. Return Values ConstantValueDescription vbOK 1 OK vbCancel 2 Cancel vbAbort 3 Abort vbRetry 4 Retry vbIgnore 5 Ignore vbYes 6 Yes vbNo 7 No

  5. Keyboard Processes

  6. Low Level Keyboard Handlers • Three events recognized by forms and any control that accepts keyboard input • KeyDown - As any key is pressed • KeyUp - as any key is released • KeyPress -When any ASCII Character key is pressed • Only the object that has the focus can accept a key event • A Form has the focus only if the form is active and no control on the form has the focus

  7. KeyPress Event • Is passed only the integer ASCII equivalent of the key pressed and no other information. • Not all keys generate a KeyPress event - only those which have an ASCII equivalent • numbers, letters, punctuation, BACKSPACE, TAB, Ctrl-a through Ctrl-z, Ctrl-[, Ctrl-], Ctrl-BACKSPACE • ESC (unless there is a command button with Cancel = True) • ENTER (unless there is a command button with Default = True) • For example, to force all characters in a textbox to be uppercase as entered: Private sub text1_keypress(KeyAscii as Integer) KeyAscii = Asc(Ucase(Chr(KeyAscii))) end Sub

  8. KeyDown and KeyUp Events • Different from keypress in a similar way that mouseup/down is different from the click event • KeyUp/Down report the exact physical state of the keyboard itself • You must interpret what that state represents • example: KeyPress treats a and A as two separate characters, returning different codes. The KeyUp/Down will return the same code for both. • Exceptions • ESC if there is a command button with Cancel = True • ENTER if there is a command button with Default = True • TAB • Any key for which a menu Shortcut key has been defined

  9. KeyDown and KeyUp Events (2) • The KeyUp/Down events receive two arguments • keycode - indicates the physical key pressed • a and A are the same Key and return the same code • 2 on the typewriter keypad and 2 on the numeric keypad are different keys and return different codes • Use the vbConstants to refer to them (use the Object Browser). For example: vbKey2, vbKeyHome, vbKeyNumpad2 • keycodes for the letter keys are the same as the ANSI codes of the uppercase letter • keycodes for the number and punctuation keys are the same as the ANSI code of the number on the key

  10. KeyDown and KeyUp Events (3) • Shift - almost the same as Shift for mouse events with the value • 1 indicating the Shift key was depressed • 2 indicating the Ctrl key was pressed • 4 indicating the Alt key was pressed • All 8 combinations are possible (0-7)

  11. Option Buttons • Used in situations where you want to limit the user to only one of two or more related and mutually exclusive choices. • Only one in a group can be selected (on) at any one time. • When selected, an option button’s Value property contains the Boolean value True; otherwise it contains the Boolean value False.

  12. Option Buttons • Minimum number in an interface is two • Recommended maximum number is seven • Use sentence capitalization for the caption • Assign a unique access key • A default button should be selected when the interface first appears.

  13. Option Buttons • You must use a frame control if you want the interface to contain more than one group of option buttons • Set the TabIndex property of the option buttons in each group so that the user can use the up and down arrow keys to select another button in the group.

  14. Frame Control • Acts as a container for other controls • Used to visually separate controls from one another • The frame and the controls contained within the frame are treated as one unit • You must use a frame control if you want to have more than one group of option buttons • Use sentence capitalization for the optional caption

  15. Check Box • Used in situations where you want to allow the user to select any number of choices from one or more independent and non-exclusive choices. • Any number of check boxes can be selected at any one time. • When selected, a check box’s Value property contains the number 1 (vbChecked). When unselected, it contains the number 0 (vbUnchecked).

  16. Check Box • Use sentence capitalization for the check box’s Caption • Assign a unique access to each check box • You also can use the spacebar to select/deselect a check box that has the focus

More Related