Toon posts:

[VB] Only numeric

Pagina: 1
Acties:

Verwijderd

Topicstarter
Ik ben nu, na lange tijd, weer eens met Visual Basic aan het klooien. Nu ben ik vergeten wat de code is om ervoor te zorgen dat allen cijfertjes in een textbox ingevuld kan worden.
Ik heb dus een textbox en ik wil dat als iemand op een letter drukt, dat er gewoon nix komt te staan. Natuurlijk moet backspace wel werken. Mocht je een foutje maken moet je wel met backspace terug kunnen.

Ook wil ik dat als ik op Enter druk dat hij cmdOK1.setfocus uitvoerd. Ik wil dus niet op tab drukken, of met de muis de command button aanwijzen, maar dat hij met een enter automatisch doorgaat naar de command button.

Can someone help me plies :)

  • WimB
  • Registratie: Juli 2001
  • Laatst online: 30-03-2024
Zoiets:
code:
1
2
3
4
5
Private Sub Text1_KeyPress (KeyAscii As Integer)
  If KeyAscii > 26 And InStr("0123456789", Chr(KeyAscii)) = 0 Then
    KeyAscii = 0
  End If
End Sub

Die > 26 dient ervoor om te zorgen dat de gebruiker de systeemtoetsen (zoals delete) nog kan gebruiken

  • WimB
  • Registratie: Juli 2001
  • Laatst online: 30-03-2024
Of zoiets:
code:
1
2
3
4
5
Private Sub Text1_KeyPress (KeyAscii As Integer)
  If KeyAscii > 26 And Not IsNumeric(Chr(KeyAscii)) Then
    KeyAscii = 0
  End If
End Sub

Verwijderd

Topicstarter
Bedankt.
Nu mijn enter nog.....

Verwijderd

Hint: de ascii code voor een enter is vbKeyReturn (13).

Verwijderd

Is dit een idee?
code:
1
2
3
4
5
6
7
Private Sub Text1_KeyPress (KeyAscii As Integer)
  If KeyAscii = 13 then
    cmdOK1.setfocus
  ElseIf KeyAscii > 26 And Not IsNumeric(Chr(KeyAscii)) Then
    KeyAscii = 0
  End If
End Sub

Verwijderd

Bah gelijk een stuk cut'n'paste code geven wat flauw, ik geef niet voor niets alleen een korte hint :(

  • Mir
  • Registratie: Maart 2001
  • Niet online

Mir

Enter:

Je knop op Default = true zetten
Pagina: 1