Writing Code for the Form
Visual Basic can insert code templates for event procedures for
controls. You modify the code template to specify what you want to
happen when an event occurs, such as when users click the OK
button.
1. Double-click the OK button on the form to open the Code
window containing an event procedure for this control.
The name of the event procedure, bOK_Click, is a
combination of the control's name as speci#ed in the control's
Name property, an underscore (_), and the name of the event.
The Click procedure is the default procedure for a command
button.
2. Type, or copy and paste, these declarations above Private
Sub bOK_Click().
Public depth As Double
Public radius As Double
3. Type, or copy and paste, this code between Private Sub
bOK_Click() and End Sub.
' Make sure that the text in the two text boxes on the
' form, txtDepth and txtRadius, is numerical
If IsNumeric(txtDepth.text) And IsNumeric(txtRadius.text) Then
depth = txtDepth.text
radius = txtRadius.text
' Close the dialog box and continue
Hide
Else
' Display a message box telling users to enter numerical
' values for both depth and radius
MsgBox "You must enter numeric values for both depth and radius."
End If
Writing Code for the Form
(continued)
- 1
- 2
- 3
- 4
- 5
前往页