Ciao, visto che questo thread si riaggancia alll'altro tuo thread http://forum.html.it/forum/showthrea...readid=858906,
Visto che tu usi array di controlli textBox, per ottimizzare il tutto e risolvere il tuo problema, ti posto un progetto che ho buttato giù al momento completo e ottimizzato per l'inserimento e controllo delle estrazioni..magari da rivedere e ottimizzarlo per le tue esigenze.
codice:Option Explicit Private Declare Function GetWindowLong Lib "User32.dll" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long Private Declare Function SetWindowLong Lib "User32.dll" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long Const GWL_STYLE As Long = (-16) Const ES_NUMBER As Long = &H2000 Dim defStyle As Long Private Sub SetNumeric(tHwnd As Long) SetWindowLong tHwnd, GWL_STYLE, defStyle Or ES_NUMBER End Sub Private Sub SetTextNumber() Dim i As Integer For i = 0 To Text1.Count - 1 SetNumeric Text1(i).hwnd Next End Sub 'controlla che siano state inserite tutte le estrazioni Private Function InserimentoOk() As Boolean Dim i As Integer InserimentoOk = True For i = 0 To Text1.Count - 1 If Val(Text1(i)) = 0 Then InserimentoOk = False MsgBox "Non sono state inserite tutte le estrazioni!" Text1(i).SetFocus Exit For End If Next End Function Private Sub btnSalvaDati_Click() 'prima di procedere al salvataggio dei dati, controlla che siano state inserite tutte le estrazioni If InserimentoOk Then 'procedura per salvare i dati End If End Sub 'controlla che non sia stato ripetuto il numero sulla stessa ruota Private Function CheckNumber(indexTxt As Integer) As Boolean Dim i As Integer Dim idxTxt As Integer CheckNumber = False Select Case indexTxt Case 0 To 4 idxTxt = 0 Case 5 To 9 idxTxt = 5 Case 10 To 14 idxTxt = 10 Case 15 To 19 idxTxt = 15 Case 20 To 24 idxTxt = 20 Case 25 To 29 idxTxt = 25 Case 30 To 34 idxTxt = 30 Case 35 To 39 idxTxt = 35 Case 40 To 44 idxTxt = 40 Case 45 To 49 idxTxt = 45 End Select For i = idxTxt To (idxTxt + 4) If Not i = indexTxt Then If Text1(i).Text = Text1(indexTxt) Then CheckNumber = True Exit For End If End If Next End Function Private Sub Form_Load() 'Inizializzazione delle textBox relative alle estrazioni, ad accettare solo numeri defStyle = GetWindowLong(Text1(0).hwnd, GWL_STYLE) SetTextNumber End Sub Private Sub Text1_Change(Index As Integer) If Len(Text1(Index)) = 2 Then 'attenzione, la proprietà TabIndex delle textBox relative alle estrazioni,devono essere sequenziali dalla prima all'ultima SendKeys "{TAB}", True End If End Sub Private Sub Text1_Validate(Index As Integer, Cancel As Boolean) 'attenzione, la proprietà Maxlength delle textBox relative alle estazione, deve essere impostata a 2 If Len(Trim(Text1(Index).Text)) > 0 Then If Len(Text1(Index).Text) = 1 And Not Val(Text1(Index).Text) = 0 Then Text1(Index).Text = "0" & Text1(Index).Text End If If Val(Text1(Index).Text) < 1 Or Val(Text1(Index).Text) > 90 Then MsgBox "L'estrazione deve essere compresa tra 1 e 90" Text1(Index).Text = "" Cancel = True ElseIf CheckNumber(Index) Then MsgBox "Il numero [" & Text1(Index) & "] è già inserito!" Text1(Index).Text = "" Cancel = True End If End If End Sub![]()

Rispondi quotando