Sample Code 7
Code in Visual Basic form FormInputData.
'FormInputData
Option Explicit
Public MaxValue As Integer
Public MinValue As Integer
Public OpCanceled As Boolean
Private Sub cmdCancel_Click()
OpCanceled = True
Me.Hide
End Sub
Private Sub cmdCompute_Click()
Dim InvalidValue As Boolean
txtInputValue_Validate InvalidValue
If Not InvalidValue Then
OpCanceled = False
Me.Hide
End If
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If UnloadMode = vbFormControlMenu Then
Cancel = True
OpCanceled = True
Me.Hide
End If
End Sub
Private Sub txtInputValue_Validate(Cancel As Boolean)
On Error GoTo ErrorHndl
'Check that value entered is between the limits
If Int(txtInputValue.Text) < MinValue Or _
Int(txtInputValue.Text) > MaxValue Then
MsgBox "You must enter a value between " & MinValue & " and " & MaxValue
Cancel = True
End If
Exit Sub
ErrorHndl:
MsgBox "The value you entered is invalid"
Cancel = True
End Sub