home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 27 / IOPROG_27.ISO / COMMON / UIF.ZIP / Form1.frm (.txt) next >
Encoding:
Visual Basic Form  |  1998-06-01  |  7.8 KB  |  259 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "Esempio d'uso UIFValidation"
  4.    ClientHeight    =   4830
  5.    ClientLeft      =   1215
  6.    ClientTop       =   1920
  7.    ClientWidth     =   3810
  8.    LinkTopic       =   "Form1"
  9.    ScaleHeight     =   4830
  10.    ScaleWidth      =   3810
  11.    StartUpPosition =   2  'CenterScreen
  12.    Begin VB.TextBox Text5 
  13.       Height          =   315
  14.       Left            =   480
  15.       TabIndex        =   9
  16.       Top             =   3240
  17.       Width           =   2175
  18.    End
  19.    Begin VB.TextBox Text4 
  20.       Height          =   315
  21.       Left            =   480
  22.       TabIndex        =   7
  23.       Top             =   2640
  24.       Width           =   2175
  25.    End
  26.    Begin VB.CommandButton cmdOK 
  27.       Caption         =   "OK"
  28.       Height          =   375
  29.       Left            =   1260
  30.       TabIndex        =   3
  31.       Top             =   4020
  32.       Width           =   1035
  33.    End
  34.    Begin VB.TextBox Text3 
  35.       Height          =   315
  36.       Left            =   480
  37.       TabIndex        =   2
  38.       Top             =   2040
  39.       Width           =   2175
  40.    End
  41.    Begin VB.TextBox Text2 
  42.       Height          =   315
  43.       Left            =   480
  44.       TabIndex        =   1
  45.       Top             =   1260
  46.       Width           =   2175
  47.    End
  48.    Begin VB.TextBox Text1 
  49.       Height          =   315
  50.       Left            =   480
  51.       TabIndex        =   0
  52.       Top             =   600
  53.       Width           =   2175
  54.    End
  55.    Begin VB.Label Label6 
  56.       Caption         =   "Text5"
  57.       Height          =   255
  58.       Index           =   4
  59.       Left            =   2940
  60.       TabIndex        =   15
  61.       Top             =   3300
  62.       Width           =   1035
  63.    End
  64.    Begin VB.Label Label6 
  65.       Caption         =   "Text4"
  66.       Height          =   255
  67.       Index           =   3
  68.       Left            =   2940
  69.       TabIndex        =   14
  70.       Top             =   2670
  71.       Width           =   1035
  72.    End
  73.    Begin VB.Label Label6 
  74.       Caption         =   "Text3"
  75.       Height          =   255
  76.       Index           =   2
  77.       Left            =   2940
  78.       TabIndex        =   13
  79.       Top             =   2040
  80.       Width           =   1035
  81.    End
  82.    Begin VB.Label Label6 
  83.       Caption         =   "Text2"
  84.       Height          =   255
  85.       Index           =   1
  86.       Left            =   2940
  87.       TabIndex        =   12
  88.       Top             =   1290
  89.       Width           =   1035
  90.    End
  91.    Begin VB.Label Label6 
  92.       Caption         =   "Text1"
  93.       Height          =   255
  94.       Index           =   0
  95.       Left            =   2940
  96.       TabIndex        =   11
  97.       Top             =   660
  98.       Width           =   1035
  99.    End
  100.    Begin VB.Label Label5 
  101.       Caption         =   "Nessun controllo"
  102.       Height          =   255
  103.       Left            =   480
  104.       TabIndex        =   10
  105.       Top             =   3060
  106.       Width           =   1575
  107.    End
  108.    Begin VB.Label Label4 
  109.       Caption         =   "Accetta tutto eccetto Null"
  110.       Height          =   255
  111.       Left            =   480
  112.       TabIndex        =   8
  113.       Top             =   2400
  114.       Width           =   1995
  115.    End
  116.    Begin VB.Label Label3 
  117.       Caption         =   "Richiesta validazione inesistente per dimenticanza"
  118.       Height          =   435
  119.       Left            =   480
  120.       TabIndex        =   6
  121.       Top             =   1620
  122.       Width           =   1995
  123.    End
  124.    Begin VB.Label Label2 
  125.       Caption         =   "Accetta 'b'. Null non permesso"
  126.       Height          =   255
  127.       Left            =   480
  128.       TabIndex        =   5
  129.       Top             =   1020
  130.       Width           =   2295
  131.    End
  132.    Begin VB.Label Label1 
  133.       Caption         =   "Accetta 'a' o Null"
  134.       Height          =   255
  135.       Left            =   480
  136.       TabIndex        =   4
  137.       Top             =   360
  138.       Width           =   1815
  139.    End
  140. Attribute VB_Name = "Form1"
  141. Attribute VB_GlobalNameSpace = False
  142. Attribute VB_Creatable = False
  143. Attribute VB_PredeclaredId = True
  144. Attribute VB_Exposed = False
  145. 'Esempio uso UIFValidation
  146. 'Rik 24/5/98
  147. Dim UIFActive As Control
  148. Private Sub UIFValidation()
  149.     Static Valid As Boolean
  150.     'Quando un controllo non viene validato si ha una
  151.     'seconda chiamata a questa sub dalla Text successiva.
  152.     'In questo caso pero` esco senza fare niente.
  153.     If Me.ActiveControl Is UIFActive Then Exit Sub
  154.     Valid = True 'fino a prova contraria
  155.     Select Case UIFActive.Name
  156.         Case "Text1"
  157.             If Text1 <> "" And Text1 <> "a" Then
  158.                 Valid = False
  159.                 MsgBox "Devi inserire 'a' o Null"
  160.             End If
  161.         Case "Text2"
  162.             If Text2 <> "b" Then
  163.                 Valid = False
  164.                 MsgBox "Devi obbligatoriamente inserire 'b'"
  165.             End If
  166.         'Fingo di dimenticare l'inserimento richiesto
  167.         'del controllo per Text3
  168.         Case "Text4"
  169.             If Text4 = "" Then
  170.                 Valid = False
  171.                 MsgBox "Devi inserire qualcosa"
  172.             End If
  173.         'Text5 non ha controlli
  174.     Case Else
  175.         'Se siamo qui e` perche`
  176.         'un Control ha richiesto una validazione che non e`
  177.         'pero` stata inserita nel select case.
  178.         
  179.         'Inseriamo un Doevents altrimenti non si ha il GotFocus
  180.         'nel nuovo campo ed il programma resta bloccato +
  181.         'avvisiamo della dimenticanza (in maniera
  182.         'piu` o meno mascherata per il cliente...).
  183.         DoEvents
  184.         MsgBox "Il controllo " & Me.Name & "." & UIFActive.Name & _
  185.         " ha richiesto un controllo di validazione inesistente. " & _
  186.         "Avvisare il programmatore.", _
  187.         vbCritical, "Errore controllo validazione"
  188.     End Select
  189.       
  190.     If Valid = False Then UIFActive.SetFocus
  191. End Sub
  192. Private Sub UIFEmpty()
  193.     'Controllo campi obbligatori.
  194.     'Sappiamo che grazie ai controlli di UIFValidation
  195.     'tutto quello che e` gia` stato inserito e` sicuramente
  196.     'valido. Resta quindi solo da indicare all'utente che
  197.     'deve compilare altri campi.
  198.     'Vediamo quali sono quelli vuoti
  199.     '=== Se sono da controllare diversi campi, ma non tutti ===
  200.     '=== usare questo sistema
  201.     cmdOK.Enabled = False 'Default
  202.     If Text1 = "" Then Exit Sub
  203.     If Text2 = "" Then Exit Sub
  204.     'Se siamo arrivati qui allora
  205.     'siamo proprio sull'ultimo campo da riempire
  206.     'ed abbiamo appena premuto un tasto
  207.     cmdOK.Enabled = True
  208.     '=== Se sono da controllare tutti i campi ===
  209.     '=== usare questo sistema
  210. '    Dim ControlX As Control
  211. '    Dim LeftOut As Boolean
  212. '    LeftOut = False
  213. '    For Each ControlX In Controls
  214. '        If TypeOf ControlX Is TextBox Then
  215. '            If ControlX.Text = "" Then
  216. '                LeftOut = True
  217. '                Exit For
  218. '            End If
  219. '        End If
  220. '    Next
  221. '    If LeftOut Then cmdOK.Enabled = False Else cmdOK.Enabled = True
  222. End Sub
  223. Private Sub cmdOK_Click()
  224.     MsgBox "Salvataggio dati effettuato"
  225. End Sub
  226. Private Sub Form_Load()
  227.     cmdOK.Enabled = False
  228. End Sub
  229. Private Sub Text1_Change()
  230.  UIFEmpty
  231. End Sub
  232. Private Sub Text1_GotFocus()
  233.     Set UIFActive = Me.ActiveControl
  234. End Sub
  235. Private Sub Text1_LostFocus()
  236.     UIFValidation
  237. End Sub
  238. Private Sub Text2_Change()
  239.     UIFEmpty
  240. End Sub
  241. Private Sub Text2_GotFocus()
  242.     Set UIFActive = Me.ActiveControl
  243. End Sub
  244. Private Sub Text2_LostFocus()
  245.     UIFValidation
  246. End Sub
  247. Private Sub Text3_GotFocus()
  248.     Set UIFActive = Me.ActiveControl
  249. End Sub
  250. Private Sub Text3_LostFocus()
  251.     UIFValidation
  252. End Sub
  253. Private Sub Text4_GotFocus()
  254.     Set UIFActive = Me.ActiveControl
  255. End Sub
  256. Private Sub Text4_LostFocus()
  257.     UIFValidation
  258. End Sub
  259.