Página 1 de 1

Máscara de PIS

Enviado: 12 Mar 2020 às 22:32
por eloirfabio
Olá.
Estou tentando fazer uma máscara para PIS, no formato 000.00000.00-0, adaptando de uma máscara de CPF, porém, o traço não está saindo no final, somente pontos. Não sei muito bem onde está o erro. Caso alguém possa ajudar, ficarei agradecido.
Segue o código abaixo:
Código: Selecionar todos
Private Sub txtPIS_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
    'Limita a Qde de caracteres
    txtPIS.MaxLength = 14
 
     Select Case KeyAscii
        Case 8, 48 To 57 ' BackSpace e numericos
          If Len(txtPIS) = 3 Or Len(txtPIS) = 12 Then
            txtPIS.Text = txtPIS.Text & "."
            SendKeys "{End}", False
 
        ElseIf Len(txtPIS) = 9 Then
            txtPIS.Text = txtPIS.Text & "."
 
        ElseIf Len(txtPIS) = 3 Then
            txtPIS.Text = txtPIS.Text & "-"
            SendKeys "{End}", False
          End If
 
        Case Else ' o resto é travado
            KeyAscii = 0
      End Select
End Sub

Re: Máscara de PIS

Enviado: 15 Mar 2020 às 11:45
por fcarlosc2018
Bom dia

Tente assim:
Código: Selecionar todos
Private Sub txtPIS_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
    ''Limita a Qde de caracteres
    txtPIS.MaxLength = 14
 
     Select Case KeyAscii
        Case 8, 48 To 57 ' BackSpace e numericos
          If Len(txtPIS) = 3 Or Len(txtPIS) = 13 Then
            txtPIS.Text = txtPIS.Text & "."
            SendKeys "{End}", False
 
        ElseIf Len(txtPIS) = 9 Then
            txtPIS.Text = txtPIS.Text & "."
 
        ElseIf Len(txtPIS) = 12 Then
            txtPIS.Text = txtPIS.Text & "-"
            SendKeys "{End}", False
          End If
 
        Case Else ' o resto é travado
            KeyAscii = 0
      End Select
End Sub

Att,
Francisco

Máscara de PIS

Enviado: 16 Mar 2020 às 17:13
por eloirfabio
Vlw amigo! Ficou perfeito, muito obrigado.