Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
TextBox and numeric Input
Message
 
À
18/01/2000 09:07:34
Information générale
Forum:
Visual Basic
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00319402
Message ID:
00319418
Vues:
11
>I have three textboxes. The user can insert his/her birthday.
>Textbox 1 for day
>Textbox 2 for month
>Textbox 3 for year
>
>I've set the dataformat NUMBER for each textbox. Yet still the
>user can insert all characters. Is there a way to control this
>input so only numbers are allowed ?

The DataFormat property is only good when controls are bounded.

To only accept numeric values in text box use this:
Private Sub Text1_KeyPress(KeyAscii As Integer)
    If (Chr$(KeyAscii) >= "0" And Chr$(KeyAscii) <= "9") Or _
       KeyAscii = vbKeyBack _
    Then
        'Do nothing
    Else
        KeyAscii = 0
    End If
End Sub
Éric Moreau, MCPD, Visual Developer - Visual Basic MVP
Conseiller Principal / Senior Consultant
Moer inc.
http://www.emoreau.com
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform