home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Begin VB.Form Form1
- Caption = "Esempio d'uso UIFValidation"
- ClientHeight = 4830
- ClientLeft = 1215
- ClientTop = 1920
- ClientWidth = 3810
- LinkTopic = "Form1"
- ScaleHeight = 4830
- ScaleWidth = 3810
- StartUpPosition = 2 'CenterScreen
- Begin VB.TextBox Text5
- Height = 315
- Left = 480
- TabIndex = 9
- Top = 3240
- Width = 2175
- End
- Begin VB.TextBox Text4
- Height = 315
- Left = 480
- TabIndex = 7
- Top = 2640
- Width = 2175
- End
- Begin VB.CommandButton cmdOK
- Caption = "OK"
- Height = 375
- Left = 1260
- TabIndex = 3
- Top = 4020
- Width = 1035
- End
- Begin VB.TextBox Text3
- Height = 315
- Left = 480
- TabIndex = 2
- Top = 2040
- Width = 2175
- End
- Begin VB.TextBox Text2
- Height = 315
- Left = 480
- TabIndex = 1
- Top = 1260
- Width = 2175
- End
- Begin VB.TextBox Text1
- Height = 315
- Left = 480
- TabIndex = 0
- Top = 600
- Width = 2175
- End
- Begin VB.Label Label6
- Caption = "Text5"
- Height = 255
- Index = 4
- Left = 2940
- TabIndex = 15
- Top = 3300
- Width = 1035
- End
- Begin VB.Label Label6
- Caption = "Text4"
- Height = 255
- Index = 3
- Left = 2940
- TabIndex = 14
- Top = 2670
- Width = 1035
- End
- Begin VB.Label Label6
- Caption = "Text3"
- Height = 255
- Index = 2
- Left = 2940
- TabIndex = 13
- Top = 2040
- Width = 1035
- End
- Begin VB.Label Label6
- Caption = "Text2"
- Height = 255
- Index = 1
- Left = 2940
- TabIndex = 12
- Top = 1290
- Width = 1035
- End
- Begin VB.Label Label6
- Caption = "Text1"
- Height = 255
- Index = 0
- Left = 2940
- TabIndex = 11
- Top = 660
- Width = 1035
- End
- Begin VB.Label Label5
- Caption = "Nessun controllo"
- Height = 255
- Left = 480
- TabIndex = 10
- Top = 3060
- Width = 1575
- End
- Begin VB.Label Label4
- Caption = "Accetta tutto eccetto Null"
- Height = 255
- Left = 480
- TabIndex = 8
- Top = 2400
- Width = 1995
- End
- Begin VB.Label Label3
- Caption = "Richiesta validazione inesistente per dimenticanza"
- Height = 435
- Left = 480
- TabIndex = 6
- Top = 1620
- Width = 1995
- End
- Begin VB.Label Label2
- Caption = "Accetta 'b'. Null non permesso"
- Height = 255
- Left = 480
- TabIndex = 5
- Top = 1020
- Width = 2295
- End
- Begin VB.Label Label1
- Caption = "Accetta 'a' o Null"
- Height = 255
- Left = 480
- TabIndex = 4
- Top = 360
- Width = 1815
- End
- Attribute VB_Name = "Form1"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- 'Esempio uso UIFValidation
- 'Rik 24/5/98
- Dim UIFActive As Control
- Private Sub UIFValidation()
- Static Valid As Boolean
- 'Quando un controllo non viene validato si ha una
- 'seconda chiamata a questa sub dalla Text successiva.
- 'In questo caso pero` esco senza fare niente.
- If Me.ActiveControl Is UIFActive Then Exit Sub
- Valid = True 'fino a prova contraria
- Select Case UIFActive.Name
- Case "Text1"
- If Text1 <> "" And Text1 <> "a" Then
- Valid = False
- MsgBox "Devi inserire 'a' o Null"
- End If
- Case "Text2"
- If Text2 <> "b" Then
- Valid = False
- MsgBox "Devi obbligatoriamente inserire 'b'"
- End If
- 'Fingo di dimenticare l'inserimento richiesto
- 'del controllo per Text3
- Case "Text4"
- If Text4 = "" Then
- Valid = False
- MsgBox "Devi inserire qualcosa"
- End If
- 'Text5 non ha controlli
- Case Else
- 'Se siamo qui e` perche`
- 'un Control ha richiesto una validazione che non e`
- 'pero` stata inserita nel select case.
-
- 'Inseriamo un Doevents altrimenti non si ha il GotFocus
- 'nel nuovo campo ed il programma resta bloccato +
- 'avvisiamo della dimenticanza (in maniera
- 'piu` o meno mascherata per il cliente...).
- DoEvents
- MsgBox "Il controllo " & Me.Name & "." & UIFActive.Name & _
- " ha richiesto un controllo di validazione inesistente. " & _
- "Avvisare il programmatore.", _
- vbCritical, "Errore controllo validazione"
- End Select
-
- If Valid = False Then UIFActive.SetFocus
- End Sub
- Private Sub UIFEmpty()
- 'Controllo campi obbligatori.
- 'Sappiamo che grazie ai controlli di UIFValidation
- 'tutto quello che e` gia` stato inserito e` sicuramente
- 'valido. Resta quindi solo da indicare all'utente che
- 'deve compilare altri campi.
- 'Vediamo quali sono quelli vuoti
- '=== Se sono da controllare diversi campi, ma non tutti ===
- '=== usare questo sistema
- cmdOK.Enabled = False 'Default
- If Text1 = "" Then Exit Sub
- If Text2 = "" Then Exit Sub
- 'Se siamo arrivati qui allora
- 'siamo proprio sull'ultimo campo da riempire
- 'ed abbiamo appena premuto un tasto
- cmdOK.Enabled = True
- '=== Se sono da controllare tutti i campi ===
- '=== usare questo sistema
- ' Dim ControlX As Control
- ' Dim LeftOut As Boolean
- ' LeftOut = False
- ' For Each ControlX In Controls
- ' If TypeOf ControlX Is TextBox Then
- ' If ControlX.Text = "" Then
- ' LeftOut = True
- ' Exit For
- ' End If
- ' End If
- ' Next
- ' If LeftOut Then cmdOK.Enabled = False Else cmdOK.Enabled = True
- End Sub
- Private Sub cmdOK_Click()
- MsgBox "Salvataggio dati effettuato"
- End Sub
- Private Sub Form_Load()
- cmdOK.Enabled = False
- End Sub
- Private Sub Text1_Change()
- UIFEmpty
- End Sub
- Private Sub Text1_GotFocus()
- Set UIFActive = Me.ActiveControl
- End Sub
- Private Sub Text1_LostFocus()
- UIFValidation
- End Sub
- Private Sub Text2_Change()
- UIFEmpty
- End Sub
- Private Sub Text2_GotFocus()
- Set UIFActive = Me.ActiveControl
- End Sub
- Private Sub Text2_LostFocus()
- UIFValidation
- End Sub
- Private Sub Text3_GotFocus()
- Set UIFActive = Me.ActiveControl
- End Sub
- Private Sub Text3_LostFocus()
- UIFValidation
- End Sub
- Private Sub Text4_GotFocus()
- Set UIFActive = Me.ActiveControl
- End Sub
- Private Sub Text4_LostFocus()
- UIFValidation
- End Sub
-