home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 4 Power Pack / Visual_Basic4_Power_Pack.bin / vb4files / validate / valid.exe / VALIDS1.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-05-24  |  9.0 KB  |  287 lines

  1. VERSION 4.00
  2. Begin VB.Form ValidS1 
  3.    BorderStyle     =   3  'Fixed Dialog
  4.    Caption         =   "Validate Control Sample"
  5.    ClientHeight    =   5985
  6.    ClientLeft      =   1020
  7.    ClientTop       =   1425
  8.    ClientWidth     =   6645
  9.    ControlBox      =   0   'False
  10.    Height          =   6390
  11.    Left            =   960
  12.    LinkTopic       =   "Form1"
  13.    MaxButton       =   0   'False
  14.    MinButton       =   0   'False
  15.    ScaleHeight     =   5985
  16.    ScaleWidth      =   6645
  17.    ShowInTaskbar   =   0   'False
  18.    Top             =   1080
  19.    Width           =   6765
  20.    Begin VB.TextBox txtFax 
  21.       Height          =   285
  22.       Left            =   1200
  23.       TabIndex        =   7
  24.       Top             =   3000
  25.       Width           =   2775
  26.    End
  27.    Begin VB.TextBox txtPhone 
  28.       Height          =   285
  29.       Left            =   1200
  30.       TabIndex        =   6
  31.       Top             =   2640
  32.       Width           =   2775
  33.    End
  34.    Begin VB.TextBox txtZipCode 
  35.       Height          =   285
  36.       Left            =   1200
  37.       TabIndex        =   5
  38.       Top             =   2040
  39.       Width           =   1455
  40.    End
  41.    Begin VB.TextBox txtCityState 
  42.       Height          =   285
  43.       Left            =   1200
  44.       TabIndex        =   4
  45.       Top             =   1680
  46.       Width           =   2775
  47.    End
  48.    Begin VB.TextBox txtAddress2 
  49.       Height          =   285
  50.       Left            =   1200
  51.       TabIndex        =   3
  52.       Top             =   1320
  53.       Width           =   2775
  54.    End
  55.    Begin VB.TextBox txtAddress 
  56.       Height          =   285
  57.       Left            =   1200
  58.       TabIndex        =   2
  59.       Top             =   960
  60.       Width           =   2775
  61.    End
  62.    Begin VB.TextBox txtCompany 
  63.       Height          =   285
  64.       Left            =   1200
  65.       TabIndex        =   1
  66.       Top             =   600
  67.       Width           =   2775
  68.    End
  69.    Begin VB.TextBox txtName 
  70.       Height          =   285
  71.       Left            =   1200
  72.       TabIndex        =   0
  73.       Top             =   240
  74.       Width           =   2775
  75.    End
  76.    Begin VB.CommandButton btnExit 
  77.       Cancel          =   -1  'True
  78.       Caption         =   "Cancel"
  79.       Height          =   375
  80.       Left            =   4680
  81.       TabIndex        =   9
  82.       Top             =   720
  83.       Width           =   1695
  84.    End
  85.    Begin VB.CommandButton btnOK 
  86.       Caption         =   "OK"
  87.       Default         =   -1  'True
  88.       Height          =   375
  89.       Left            =   4680
  90.       TabIndex        =   8
  91.       Top             =   240
  92.       Width           =   1695
  93.    End
  94.    Begin VB.Label Label9 
  95.       Caption         =   $"VALIDS1.frx":0000
  96.       BeginProperty Font 
  97.          name            =   "MS Sans Serif"
  98.          charset         =   0
  99.          weight          =   700
  100.          size            =   8.25
  101.          underline       =   0   'False
  102.          italic          =   0   'False
  103.          strikethrough   =   0   'False
  104.       EndProperty
  105.       Height          =   1095
  106.       Left            =   480
  107.       TabIndex        =   18
  108.       Top             =   4800
  109.       Width           =   5655
  110.    End
  111.    Begin VB.Label Label8 
  112.       Caption         =   $"VALIDS1.frx":0131
  113.       BeginProperty Font 
  114.          name            =   "MS Sans Serif"
  115.          charset         =   0
  116.          weight          =   700
  117.          size            =   8.25
  118.          underline       =   0   'False
  119.          italic          =   0   'False
  120.          strikethrough   =   0   'False
  121.       EndProperty
  122.       Height          =   1095
  123.       Left            =   480
  124.       TabIndex        =   17
  125.       Top             =   3600
  126.       Width           =   5655
  127.    End
  128.    Begin VB.Label Label7 
  129.       Caption         =   "Fax:"
  130.       Height          =   255
  131.       Left            =   240
  132.       TabIndex        =   16
  133.       Top             =   3000
  134.       Width           =   855
  135.    End
  136.    Begin VB.Label Label6 
  137.       Caption         =   "Phone:"
  138.       Height          =   255
  139.       Left            =   240
  140.       TabIndex        =   15
  141.       Top             =   2640
  142.       Width           =   855
  143.    End
  144.    Begin VB.Label Label5 
  145.       Caption         =   "Zip Code:"
  146.       Height          =   255
  147.       Left            =   240
  148.       TabIndex        =   14
  149.       Top             =   2040
  150.       Width           =   855
  151.    End
  152.    Begin VB.Label Label4 
  153.       Caption         =   "City, State:"
  154.       Height          =   255
  155.       Left            =   240
  156.       TabIndex        =   13
  157.       Top             =   1680
  158.       Width           =   855
  159.    End
  160.    Begin VB.Label Label3 
  161.       Caption         =   "Address:"
  162.       Height          =   255
  163.       Left            =   240
  164.       TabIndex        =   12
  165.       Top             =   960
  166.       Width           =   855
  167.    End
  168.    Begin VB.Label Label2 
  169.       Caption         =   "Company:"
  170.       Height          =   255
  171.       Left            =   240
  172.       TabIndex        =   11
  173.       Top             =   600
  174.       Width           =   855
  175.    End
  176.    Begin VB.Label Label1 
  177.       Caption         =   "Name:"
  178.       Height          =   255
  179.       Left            =   240
  180.       TabIndex        =   10
  181.       Top             =   240
  182.       Width           =   855
  183.    End
  184.    Begin MabryValidate.Validate Validate1 
  185.       Left            =   5880
  186.       Top             =   1200
  187.       _version        =   65536
  188.       _extentx        =   847
  189.       _extenty        =   847
  190.       _stockprops     =   64
  191.    End
  192. Attribute VB_Name = "ValidS1"
  193. Attribute VB_Creatable = False
  194. Attribute VB_Exposed = False
  195. Option Explicit
  196. Dim LastFieldValid ' True if the last validation check
  197.                    ' was good.  False for bad data.
  198. Private Sub btnExit_Click()
  199.     ' Just quit the program.
  200.     End
  201.     End Sub
  202. Private Sub btnOK_Click()
  203.     ' If the last field we checked was invalid,
  204.     ' don't exit.
  205.     If LastFieldValid = False Then
  206.         Exit Sub
  207.         End If
  208.         
  209.     ' Exit.
  210.     End
  211.     End Sub
  212. Private Sub Form_Load()
  213.     ' Add the text box controls to the Validate
  214.     ' control's list of controls to watch.  This
  215.     ' will cause the Validate event to fire when
  216.     ' the user switches focus from control to
  217.     ' control (later).
  218.     Validate1.AddControl txtName
  219.     Validate1.AddControl txtCompany
  220.     Validate1.AddControl txtAddress
  221.     Validate1.AddControl txtAddress2
  222.     Validate1.AddControl txtCityState
  223.     Validate1.AddControl txtZipCode
  224.     Validate1.AddControl txtPhone
  225.     Validate1.AddControl txtFax
  226.     End Sub
  227. ' This subroutine handles all of the data validation
  228. ' for the form.
  229. Private Sub Validate1_Validate(ByVal CtrlValidate As Object, ByVal CtrlWantsFocus As Object, Activate As Long)
  230.     ' If the user pressed the Cancel button, don't
  231.     ' bother with any validation.
  232.     If CtrlWantsFocus.Name = "btnCancel" Then
  233.         Exit Sub
  234.         End If
  235.         
  236.     ' This flag lets other procedures know (mainly
  237.     ' the btnOK_Click procedure) if this field
  238.     ' is valid, or not.
  239.     LastFieldValid = True
  240.     ' How we validate depends on the data.
  241.     Select Case CtrlValidate.Name
  242.         Case "txtName", "txtAddress", "txtCityState"
  243.             ' In the case of the name and address,
  244.             ' we just want to ensure that we have data.
  245.             If Trim(CtrlValidate.Text) = "" Then
  246.                 If CtrlValidate.Name = "txtName" Then
  247.                     MsgBox "You must enter a name."
  248.                 ElseIf CtrlValidate.Name = "txtAddress" Then
  249.                     MsgBox "You must enter an address."
  250.                 Else
  251.                     MsgBox "You must enter a city and state."
  252.                     End If
  253.                     
  254.                 ' Let the system know that this is
  255.                 ' not valid data.
  256.                 LastFieldValid = False
  257.                 End If
  258.                 
  259.         Case "txtZipCode"
  260.             ' This field requires either a five digit zip code
  261.             ' or a nine digit zip code (with our without hyphen)
  262.             LastFieldValid = CheckZipCode(Trim(CtrlValidate.Text))
  263.             
  264.             If Not LastFieldValid Then
  265.                 MsgBox "'" & Trim(CtrlValidate.Text) & "' is not a valid Zip Code."
  266.                 End If
  267.         
  268.         Case "txtPhone", "txtFax"
  269.             ' These fields expect a phone number in the
  270.             ' form XXX-XXX-XXXX (if anything is present)
  271.             ' This uses the function in VALID.BAS to
  272.             ' determine the phone number's validity.
  273.             If Trim(CtrlValidate.Text) <> "" Then
  274.                 LastFieldValid = CheckPhoneNumber(Trim(CtrlValidate.Text))
  275.                 
  276.                 If Not LastFieldValid Then
  277.                     MsgBox "'" & Trim(CtrlValidate.Text) & "' is not a valid phone number."
  278.                     End If
  279.                 End If
  280.         End Select
  281.     ' If this field is not valid, don't allow focus
  282.     ' to change.
  283.     If Not LastFieldValid Then
  284.         Activate = True
  285.         End If
  286.     End Sub
  287.