Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— 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 vbOKOnly0Display OK button only. vbOKCancel1Display OK and Cancel buttons. vbAbortRetryIgnore2Display Abort, Retry, and Ignore buttons. vbYesNoCancel3Display Yes, No, and Cancel buttons. vbYesNo4Display Yes and No buttons. vbRetryCancel5Display Retry and Cancel buttons. vbCritical16Display Critical Message icon. vbQuestion32Display Warning Query icon. vbExclamation48Display Warning Message icon. vbInformation64Display Information Message icon. vbDefaultButton10First button is default. vbDefaultButton2256Second button is default. vbDefaultButton3512Third button is default. vbDefaultButton4768Fourth button is default. vbApplicationModal0Application modal; the user must respond to the message box before continuing work in the current application. vbSystemModal4096System modal; all applications are suspended until the user responds to the message box.

4 Return Values ConstantValueDescription vbOK1OK vbCancel2Cancel vbAbort3Abort vbRetry4Retry vbIgnore5Ignore vbYes6Yes vbNo7No

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


Download ppt "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."

Similar presentations


Ads by Google