Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Alex-jpa

Forçar digitação numérica no campo

Recommended Posts

GaleraEu estou precisando de uma função que só permita a digitação de dados numéricos e reiais em um determinado campo.Eu consegui colocar só para número inteiro, só que ele não aceita a ",".vocês podem me ajudar?:CÓDIGOtxtTotal_KeyPressKeyAscii = IIf(KeyAscii > 47 And KeyAscii < 58 Or KeyAscii = 8, KeyAscii, 0)abrsAlex

Compartilhar este post


Link para o post
Compartilhar em outros sites

Galera consegui

 

Fico indignado muitas das vezes aqui no fórum porque ninguém me dá uma ajuda. Mas tudo bem!

 

desculpas

 

 

Segue a função que acabei descobrindo

 

Function SoNumero(Ascii_ As Integer, Optional AceitaVirgula As Boolean = True, Optional VerObjeto As Object) As Integer

If (Ascii_ >= Asc("0") _

And Ascii_ <= Asc("9")) _

Or Ascii_ = vbKeyBack _

Or Ascii_ = vbKeyReturn Or Ascii_ = 44 Then

If AceitaVirgula = False Then

If Ascii_ = 44 Then

SoNumero = 0

Exit Function

End If

ElseIf Not VerObjeto Is Nothing Then

If Len(VerObjeto.Text) = 0 And Ascii_ = 44 Then

SoNumero = 0

Exit Function

End If

If VerObjeto.SelStart = 0 And VerObjeto.SelLength = Len(VerObjeto.Text) And Ascii_ = 44 Then

SoNumero = 0

Exit Function

End If

For i = 1 To Len(VerObjeto)

If Mid(VerObjeto.Text, i, 1) = "," And Ascii_ = 44 Then

SoNumero = 0

Exit Function

End If

Next

End If

SoNumero = Ascii_

Else

SoNumero = 0

End If

End Function

 

 

Com vírgula

BOTAO

Private Sub Text1_KeyPress(KeyAscii As Integer)

KeyAscii = SoNumero(KeyAscii, True, Text1)

End Sub

 

 

Sem vírgula

BOTAO

Private Sub Text1_KeyPress(KeyAscii As Integer)

KeyAscii = SoNumero(KeyAscii)

End Sub

 

abraços

 

 

Alex

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.