come faccio a far in modo che in una textbox possano essere inseriti solo numeri da tastiera o da tastierino numerico e il pulsante Enter, e che non possano essere inseriti tutti gli altri caratterei punti e virgole inclusi. io ho provato cosi ma non funziona... xke mi da la msg box ad ogni tasto che premo, numeri compresi...
codice:Private Sub txtNum_Keydown(KeyAscii As Integer, shift As Integer) If KeyAscii = vbKeyReturn Or vbKey0 Or vbKey1 Or vbKey2 Or vbKey3 _ Or vbKey4 Or vbKey5 Or vbKey6 Or vbKey7 Or vbKey8 Or vbKey9 Or _ vbKeyNumpad0 Or vbKeyNumpad1 Or vbKeyNumpad2 Or vbKeyNumpad3 Or _ vbKeyNumpad4 Or vbKeyNumpad5 Or vbKeyNumpad6 Or vbKeyNumpad7 Or _ vbKeyNumpad8 Or vbKeyNumpad9 Then If KeyAscii = vbKeyReturn And Val(txtNum.Text) > 0 Then Command1_click End If Else MsgBox "Valore non valido." & Chr(10) & "Inserire un valore numerico e minore di:" & Chr(13) & "'662'", vbExclamation + vbOKOnly, "Valore non valido" txtNum.Text = "" txtNum.SetFocus End If End Sub

Rispondi quotando