Aldeia RPG

Gostaria de reagir a esta mensagem? Crie uma conta em poucos cliques ou inicie sessão para continuar.

Suporte ao desenvolvimento de jogos


    Aceitando Somente Numeros em Controles TextBox ou Somente Caracteres

    Valentine
    Valentine
    Administrador
    Administrador


    Medalhas : Aceitando Somente Numeros em Controles TextBox ou Somente Caracteres ZgLkiRU
    Mensagens : 5336
    Créditos : 1163

    Aceitando Somente Numeros em Controles TextBox ou Somente Caracteres Empty Aceitando Somente Numeros em Controles TextBox ou Somente Caracteres

    Mensagem por Valentine Seg Abr 09, 2012 2:38 pm

    Se Você quiser que somente números sejam aceitos em controles TextBox, faça da seguinte forma:

    Código:
    Private Sub Text1_KeyPress(KeyAscii As Integer)
    If KeyAscii < 48 Or KeyAscii > 57 And KeyAscii <> 8 Then
    KeyAscii = 0
    End If
    End Sub

    Caso queira somente Texto então o seu código deverá ser esse.

    Código:
    Private Sub Text1_KeyPress(KeyAscii As Integer)
    If KeyAscii >= 49 And KeyAscii <= 57 And KeyAscii <> 8 Then
    KeyAscii = 0
    End If
    End Sub

    Fonte:
    http://www.vbbrasil.com.br/

      Data/hora atual: Sex Abr 19, 2024 3:02 am