Con queste due API imposti la textbox, nel Form_Load, per accettare solo numeri. Quindi non devi intercettare nulla e puoi anche usare copia incolla, se non mi sbaglio, cancellare ed inserire numeri.Codice:Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long Private Const GWL_STYLE = (-16) Private Const ES_NUMBER = &H2000& Dim i As Long i = GetWindowLong(Text1.hWnd, GWL_STYLE) Call SetWindowLong(Text1.hWnd, GWL_STYLE, i Or ES_NUMBER)
VB 6 ha poi l'evento Validate, che viene eseguito ogni volta che ti sposti a un altro campo o controllo. All'interno di questo evento controlli se il numero è valido:
Codice:Private Sub Text1_Validate(Cancel As Boolean) On Error Resume Next Select Case CInt(Text1.Text) Case 800 To 16000 Case Else Cancel = True End Select If Err.Number Then Cancel = True MsgBox "Il testo non è un numero valido!", vbExclamation ElseIf Cancel Then MsgBox "Digitare un numero fra 800 e 16000!", vbExclamation End If End Sub


!
Segnalibri