Notifications
Clear all

Limitar caracteres e formatar textbox

17 Posts
3 Usuários
0 Reactions
5,565 Visualizações
(@fernandofernandes)
Posts: 43750
Illustrious Member
Topic starter
 

No meu form tenho varios textbox que gostaria de formatar para que só aceite digitar valores numéricos com exceção da "," virgula , ficando formatado como
000,0000 ; ou seja após a virgula 4digitos porem antes da virgula até 3 digitos;

 
Postado : 26/04/2012 1:51 pm
(@fernandofernandes)
Posts: 43750
Illustrious Member
Topic starter
 

Segue o codigo para a txtbox so aceitar numero

Private Sub ComprimentoCilindrica_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Select Case KeyAscii
Case 8 'Backspace (seta de apagar)
Case 48 To 57 'Números de 0 a 9
Case 44 'Vírgula
If InStr(ComprimentoCilindrica.Text, ",") Then 'Se o campo já tiver vírgula então ele não adiciona
KeyAscii = 0 'Não adiciona a vírgula caso ja tenha
Else
KeyAscii = 44 'Adiciona uma vírgula
End If
Case Else
KeyAscii = 0 'Não deixa nenhuma outra caractere ser escrito
End Select
End Sub

para formatar basta usar a função format na saida do foco da txt box:

Private Sub txtbox_Exit(ByVal Cancel As MSForms.ReturnBoolean)
txtbox.Text = Format(Ttxtbox.Text, "###,####")

End Sub

 
Postado : 26/04/2012 4:56 pm
(@fernandofernandes)
Posts: 43750
Illustrious Member
Topic starter
 

Tentei mas não deu ,
se digito 733virgula47 ,fica só 733 , some o virgula47o
se digito 73347 fica 73ponto347
O correto seria 733,47

 
Postado : 26/04/2012 6:18 pm
(@fernandofernandes)
Posts: 43750
Illustrious Member
Topic starter
 

Boa noite!!

Veja se vai te ajudar....

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    TextBox1 = Format(TextBox1, "##0"",""####")
End Sub
 
Private Sub TextBox1_Change()
    With TextBox1
        If Not IsNumeric(.Value) And .Value <> vbNullString Then
            MsgBox "Digite Somente Número"
            .Value = vbNullString
        End If
    End With
End Sub
 
Postado : 26/04/2012 7:27 pm
(@fernandofernandes)
Posts: 43750
Illustrious Member
Topic starter
 

alexandre , agora
se digito 733virgula47 ,fica 0,0733
se digito 73347 fica 7,3347
e aceita .ponto ou ,virgula

 
Postado : 26/04/2012 8:12 pm
(@fernandofernandes)
Posts: 43750
Illustrious Member
Topic starter
 

Bom dia!!
Se não percebeu eu tentei seguir ...

No meu form tenho varios textbox que gostaria de formatar para que só aceite digitar valores numéricos com exceção da "," virgula , ficando formatado como
000,0000 ; ou seja após a virgula 4digitos porem antes da virgula até 3 digitos;

São 7 dígitos, enquanto não completar os setes você pode ter os resultados...antes da virgula.

 
Postado : 27/04/2012 4:49 am
(@fernandofernandes)
Posts: 43750
Illustrious Member
Topic starter
 

Ok , entendi ; mas estava imaginando parecido com um de data que tenho aqui , que quando digito o dia ele já insere a / ;não no comando EXIT
Pensei mais ou menos assim digito o numero 7, aparece 7,00 instantaneamente ,em seguida digito 2 ,aparece 7,20 instantaneamente ,digito 3, aparece 7,23 instantaneamente , e assim por diante ; vai "empurrando" pra esquerda a sequencia ficando os dois ultimos digitados sempre depois da virgula ; tem como?

O problema é que alem de não saber o código ainda não sei explicar o que quero , ai mato vcs de raiva né?

 
Postado : 27/04/2012 10:14 am
(@fernandofernandes)
Posts: 43750
Illustrious Member
Topic starter
 

Ah se puder comentar passo a passo , porque vou adapta-lo tambem a outros textbox onde é 3 ,4 , ou 5 casas após a virgula ; ai consigo entender quar parte "põe as casas apos a virgula".

 
Postado : 27/04/2012 10:17 am
(@fernandofernandes)
Posts: 43750
Illustrious Member
Topic starter
 

Boa noite!!
Veja se vai ajudar....

Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    With TextBox1
    Select Case Len(.Value)
        Case 2: .Value = Left(.Value, 1) & "," & Right(.Value, 1) & "0"
        Case 3: .Value = Left(.Value, 1) & "," & Mid(.Value, 2)
        Case 4: .Value = Left(.Value, 2) & "," & Mid(.Value, 3)
        Case 5, 6, 7: .Value = Left(.Value, 3) & "," & Mid(.Value, 4)
    End Select
End With
End Sub
 
Postado : 27/04/2012 5:14 pm
(@fernandofernandes)
Posts: 43750
Illustrious Member
Topic starter
 

ainda não é essa a idéia , a idéia é que em tempo real a virgula vá aparecendo , tipo sempre vai começar com 0,0x onde x é o primeiro numero digitado , e a medida que for digitando novos numeros o x vá se movendo a esquerda , exemplo : se digitar 12 ficará 0,12 se digitar 123 ficará 1,23 ;se digitar 1234567890 ficará 12345678,90

 
Postado : 27/04/2012 11:23 pm
(@fernandofernandes)
Posts: 43750
Illustrious Member
Topic starter
 

Boa tarde!!

Não consegue adaptar?..faça uma força !!!
Depois de tentar e caso não consiga retorne.
Att

 
Postado : 28/04/2012 12:40 pm
(@fernandofernandes)
Posts: 43750
Illustrious Member
Topic starter
 

to tentando mas sem sucesso , poderia me dizer o evento que devo usar , tentei o exit ,o before e o change

 
Postado : 29/04/2012 12:12 pm
(@fernandofernandes)
Posts: 43750
Illustrious Member
Topic starter
 

Valeu alexandre , quase suicidei mas consegui adaptar; é tem de tentar mesmo, não ficou como eu queria ;"virgula em tempo real" mas ficou legal

Private Sub txtVrUS_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If txtVrUS.TextLength > 6 Then
Cancel = True
MsgBox " Confira o Valor da Us", vbInformation, "::.ERRO DE DIGITAÇÃO.::"
Exit Sub
Else
If txtVrUS.TextLength = 0 Then
Cancel = True
MsgBox "Falta Valor da US", vbInformation, "::.ERRO DE DIGITAÇÃO.::"
Exit Sub
Else
With txtVrUS
Select Case Len(.Value)
Case 1: .Value = "00" & "," & "0" & Right(.Value, 1)
Case 2: .Value = "00" & "," & Right(.Value, 2)
Case 3: .Value = Left(.Value, 1) & "," & Right(.Value, 2)
Case 4: .Value = Left(.Value, 2) & "," & Right(.Value, 2)
Case 5: .Value = Left(.Value, 3) & "," & Right(.Value, 2)
Case 6: .Value = Left(.Value, 4) & "," & Right(.Value, 2)
End Select
End With
End If
End If
End Sub

 
Postado : 29/04/2012 10:16 pm
(@fernandofernandes)
Posts: 43750
Illustrious Member
Topic starter
 

Virgula em tempo real

Private Sub txtVrUS_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If txtVrUS.TextLength > 11 Then
Cancel = True
MsgBox " Confira o Valor da Us", vbInformation, "::.ERRO DE DIGITAÇÃO.::"
txtVrUS.SelStart = 0
txtVrUS.Text = ""
Exit Sub
End If
With txtVrUS
Select Case Len(.Value)
Case 1: .Value = "00" & "," & "0" & Right(.Value, 1)
Case 2: .Value = "00" & "," & Right(.Value, 2)
Case 3: .Value = Left(.Value, 1) & "," & Right(.Value, 2)
Case 4: .Value = Left(.Value, 2) & "," & Right(.Value, 2)
Case 5: .Value = Left(.Value, 3) & "," & Right(.Value, 2)
Case 6: .Value = Left(.Value, 4) & "," & Right(.Value, 2)
End Select
End With
End Sub
Private Sub txtVrUS_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
KeyAscii = SoNUMEROS(KeyAscii)
If KeyAscii = 0 Then
MsgBox "DIGITE SOMENTE NÚMEROS ", vbInformation, "::.ERRO DE DIGITAÇÃO.::"
End If
If IsNumeric(txtVrUS) = True Then
txtVrUS.Value = Replace(txtVrUS.Value, ",", "")
txtVrUS.Value = Format(txtVrUS.Value / 10, "R$ #,###,##0.0")
End If
End Sub

 
Postado : 30/04/2012 8:04 am
(@rodrigojacinto)
Posts: 73
Estimable Member
 

Boa noite
Amigos, procurei em todos topicos e nao encontrei, nao entendo de programação, por isso peço vossa ajuda...
Tenho um Textbox que preciso que ele so aceite 4 valores que seria.. 0 ou 1 ou 2 ou 3... caso o usuario nao coloque um desse valore apareça uma menssagem dizendo que so é aceito esse numeros, sera possivel?

Valeu..

 
Postado : 19/05/2012 8:59 pm
Página 1 / 2