home *** CD-ROM | disk | FTP | other *** search
- VERSION 4.00
- Begin VB.Form ValidS1
- BorderStyle = 3 'Fixed Dialog
- Caption = "Validate Control Sample"
- ClientHeight = 5985
- ClientLeft = 1020
- ClientTop = 1425
- ClientWidth = 6645
- ControlBox = 0 'False
- Height = 6390
- Left = 960
- LinkTopic = "Form1"
- MaxButton = 0 'False
- MinButton = 0 'False
- ScaleHeight = 5985
- ScaleWidth = 6645
- ShowInTaskbar = 0 'False
- Top = 1080
- Width = 6765
- Begin VB.TextBox txtFax
- Height = 285
- Left = 1200
- TabIndex = 7
- Top = 3000
- Width = 2775
- End
- Begin VB.TextBox txtPhone
- Height = 285
- Left = 1200
- TabIndex = 6
- Top = 2640
- Width = 2775
- End
- Begin VB.TextBox txtZipCode
- Height = 285
- Left = 1200
- TabIndex = 5
- Top = 2040
- Width = 1455
- End
- Begin VB.TextBox txtCityState
- Height = 285
- Left = 1200
- TabIndex = 4
- Top = 1680
- Width = 2775
- End
- Begin VB.TextBox txtAddress2
- Height = 285
- Left = 1200
- TabIndex = 3
- Top = 1320
- Width = 2775
- End
- Begin VB.TextBox txtAddress
- Height = 285
- Left = 1200
- TabIndex = 2
- Top = 960
- Width = 2775
- End
- Begin VB.TextBox txtCompany
- Height = 285
- Left = 1200
- TabIndex = 1
- Top = 600
- Width = 2775
- End
- Begin VB.TextBox txtName
- Height = 285
- Left = 1200
- TabIndex = 0
- Top = 240
- Width = 2775
- End
- Begin VB.CommandButton btnExit
- Cancel = -1 'True
- Caption = "Cancel"
- Height = 375
- Left = 4680
- TabIndex = 9
- Top = 720
- Width = 1695
- End
- Begin VB.CommandButton btnOK
- Caption = "OK"
- Default = -1 'True
- Height = 375
- Left = 4680
- TabIndex = 8
- Top = 240
- Width = 1695
- End
- Begin VB.Label Label9
- Caption = $"VALIDS1.frx":0000
- BeginProperty Font
- name = "MS Sans Serif"
- charset = 0
- weight = 700
- size = 8.25
- underline = 0 'False
- italic = 0 'False
- strikethrough = 0 'False
- EndProperty
- Height = 1095
- Left = 480
- TabIndex = 18
- Top = 4800
- Width = 5655
- End
- Begin VB.Label Label8
- Caption = $"VALIDS1.frx":0131
- BeginProperty Font
- name = "MS Sans Serif"
- charset = 0
- weight = 700
- size = 8.25
- underline = 0 'False
- italic = 0 'False
- strikethrough = 0 'False
- EndProperty
- Height = 1095
- Left = 480
- TabIndex = 17
- Top = 3600
- Width = 5655
- End
- Begin VB.Label Label7
- Caption = "Fax:"
- Height = 255
- Left = 240
- TabIndex = 16
- Top = 3000
- Width = 855
- End
- Begin VB.Label Label6
- Caption = "Phone:"
- Height = 255
- Left = 240
- TabIndex = 15
- Top = 2640
- Width = 855
- End
- Begin VB.Label Label5
- Caption = "Zip Code:"
- Height = 255
- Left = 240
- TabIndex = 14
- Top = 2040
- Width = 855
- End
- Begin VB.Label Label4
- Caption = "City, State:"
- Height = 255
- Left = 240
- TabIndex = 13
- Top = 1680
- Width = 855
- End
- Begin VB.Label Label3
- Caption = "Address:"
- Height = 255
- Left = 240
- TabIndex = 12
- Top = 960
- Width = 855
- End
- Begin VB.Label Label2
- Caption = "Company:"
- Height = 255
- Left = 240
- TabIndex = 11
- Top = 600
- Width = 855
- End
- Begin VB.Label Label1
- Caption = "Name:"
- Height = 255
- Left = 240
- TabIndex = 10
- Top = 240
- Width = 855
- End
- Begin MabryValidate.Validate Validate1
- Left = 5880
- Top = 1200
- _version = 65536
- _extentx = 847
- _extenty = 847
- _stockprops = 64
- End
- Attribute VB_Name = "ValidS1"
- Attribute VB_Creatable = False
- Attribute VB_Exposed = False
- Option Explicit
- Dim LastFieldValid ' True if the last validation check
- ' was good. False for bad data.
- Private Sub btnExit_Click()
- ' Just quit the program.
- End
- End Sub
- Private Sub btnOK_Click()
- ' If the last field we checked was invalid,
- ' don't exit.
- If LastFieldValid = False Then
- Exit Sub
- End If
-
- ' Exit.
- End
- End Sub
- Private Sub Form_Load()
- ' Add the text box controls to the Validate
- ' control's list of controls to watch. This
- ' will cause the Validate event to fire when
- ' the user switches focus from control to
- ' control (later).
- Validate1.AddControl txtName
- Validate1.AddControl txtCompany
- Validate1.AddControl txtAddress
- Validate1.AddControl txtAddress2
- Validate1.AddControl txtCityState
- Validate1.AddControl txtZipCode
- Validate1.AddControl txtPhone
- Validate1.AddControl txtFax
- End Sub
- ' This subroutine handles all of the data validation
- ' for the form.
- Private Sub Validate1_Validate(ByVal CtrlValidate As Object, ByVal CtrlWantsFocus As Object, Activate As Long)
- ' If the user pressed the Cancel button, don't
- ' bother with any validation.
- If CtrlWantsFocus.Name = "btnCancel" Then
- Exit Sub
- End If
-
- ' This flag lets other procedures know (mainly
- ' the btnOK_Click procedure) if this field
- ' is valid, or not.
- LastFieldValid = True
- ' How we validate depends on the data.
- Select Case CtrlValidate.Name
- Case "txtName", "txtAddress", "txtCityState"
- ' In the case of the name and address,
- ' we just want to ensure that we have data.
- If Trim(CtrlValidate.Text) = "" Then
- If CtrlValidate.Name = "txtName" Then
- MsgBox "You must enter a name."
- ElseIf CtrlValidate.Name = "txtAddress" Then
- MsgBox "You must enter an address."
- Else
- MsgBox "You must enter a city and state."
- End If
-
- ' Let the system know that this is
- ' not valid data.
- LastFieldValid = False
- End If
-
- Case "txtZipCode"
- ' This field requires either a five digit zip code
- ' or a nine digit zip code (with our without hyphen)
- LastFieldValid = CheckZipCode(Trim(CtrlValidate.Text))
-
- If Not LastFieldValid Then
- MsgBox "'" & Trim(CtrlValidate.Text) & "' is not a valid Zip Code."
- End If
-
- Case "txtPhone", "txtFax"
- ' These fields expect a phone number in the
- ' form XXX-XXX-XXXX (if anything is present)
- ' This uses the function in VALID.BAS to
- ' determine the phone number's validity.
- If Trim(CtrlValidate.Text) <> "" Then
- LastFieldValid = CheckPhoneNumber(Trim(CtrlValidate.Text))
-
- If Not LastFieldValid Then
- MsgBox "'" & Trim(CtrlValidate.Text) & "' is not a valid phone number."
- End If
- End If
- End Select
- ' If this field is not valid, don't allow focus
- ' to change.
- If Not LastFieldValid Then
- Activate = True
- End If
- End Sub
-