Chapter Summary

• Expressions can be used to build conditions that evaluate to True or False.

• VBA conditions are built with If blocks and Select Case structures.

• Compound conditions have two or more conditions and are built using the operators And, Or, and Not.

• The Select Case structure is useful for checking an expression against a list of values.

• The Case statements in a Select Case structure can check a single value, multiple values, or a range of values.

• VBA contains the built in functions MsgBox and InputBox for building dialog boxes.

• The MsgBox function returns an integer value, whereas the InputBox function returns a string.

• The option group control contains a useful wizard for building groups of option buttons, check boxes, and toggle buttons.

• In an option group, a user can select only one check box, toggle button, or option button at a time.

Programming Challenges

1. Construct a simple math quiz that asks a user to answer a math problem of your choice. On the form, place one text box (txtAnswer) and two command buttons (cmdAskQuestion and cmdVerifyAnswer). Store the correct answer as a module-level constant and assign the user's answer in a local or procedure-level variable. Write code in the Click event of one command button to display a math question to the user with a message box. Write code in the other command button's Click event to compare the user's response to the module-level constant and inform the user of the results (correct or incorrect) also using a message box.


Programming Challenges (continued)

2. Construct another quiz program, this time using an input box to ask the question and return the user's answer. Reveal the user's result in the form of a message box. Remember to check for an empty string (user presses the Cancel button) before checking the user's response.

3. Enhance the Hangman program to allow the player multiple chances to win. More specifically, display a message box that gives the player a Yes or No option to restart the game only if the game were lost.

4. Create a simple word processor that allows a user to enter text into a large text box. (Hint: Set the Enter Key Behavior property of a text box to New Line in Field.) The user should be able to change the foreground and background colors of the text box using option buttons in an option frame. Also, the user should be able to change the font size of the text box using option buttons in another option frame.

0 0

Post a comment