
Ross Sheppard High School
Computer Programming 20
Student Learning Guide
The Dialog Box Program
| When you have finished this project, you will be able to: | ||
| use a MessageBox | ||
| use an If . . . Then | ||
|
describe the following terms:
|

| The Dialog Box Program When the user presses any of the buttons, btnYesNo, for example, a meesage "you clicked the YesNo button will appear in the TextBox txtUserChoice. A Dialog Box will also appear giving the user buttons containing the choices listed on the btnYesNo button. When the CommandButton btnExit is pressed the program will create a dialog box asking the user "Are you sure you want to quit?" Depending on the user's choice, the program will return the user to it or end. |
|
Object |
Property |
Setting |
| Form | Name | frmDialogBox |
| Caption | The Dialog Box Program | |
| Background Color | Cyan | |
| Startup Position | Screen Center | |
| TextBox | Name | txtUserChoice |
| Text | Make it blank | |
| Forecolor (Font Color) |
Red | |
| Font | Ms Sanserif 12 | |
| CommandButton | Name | btnYesNo |
| Caption | YesNo | |
| CommandButton | Name | btnOKCancel |
| Caption | OKCancel | |
| CommandButton | Name | btnOK |
| Caption | OK | |
| CommandButton | Name | btnRetryCancel |
| Caption | RetryCancel | |
| CommandButton | Name | btnExit |
| Caption | Exit | |
| Font | MS SansSerif Bold 14 |

'The next line places the message in the
'TextBox txtUserChoice>txtUserChoice.Text = "You clicked the YesNo Button"
Note: the above code starting with Response should be on a single line. When you see code with the _ character, type it on a single line. The _ indicates that the code could not fit on one line in the example above.'The next line displays the YesNo dialog box
Response = MsgBox("You pressed the YesNo button",_
vbQuestion + vbYesNo, "The YesNo Dialog Box")

'The following code defines the variable called Response
'which is the selection the user makes on the Dialog BoxDim Response As Integer
Save your project and try both buttons.'The next lines use the user's choice to display a message in the
'TextBox txtUserChoice based on the button clickedIf Response = vbYes Then
txtUserChoice.Text = "You chose the Yes Button"
Else
txtUserChoice.Text = "You chose the No Button"
End If
You should read the above statement "If the user makes this selection, then perform this procedure; otherwise perform a different procedure."If this event happens Then
Do this procedure
Else
Do a different procedure
End If
| Constant Name | Icon Displayed | Sample of icon |
| vbCritical | Critical Icon |
|
| vbQuestion | Question Icon |
|
| vbExclamation | Warning Message Icon |
|
| vbInformation | Information Icon |
|
| Constant Name | Button Displayed |
| vbOKOnly | OK |
| vbOKCancel | OK and Cancel |
| vbAbortRetryIgnore | Abort, Retry, and Ignore |
| vbYesNoCancel | Yes, No, and Cancel |
| vbYesNo | Yes and No |
| vbRetryCancel | Retry and Cancel |