InicioInfoTextbox con mascara (vb 6 - para números de DNI)

Textbox con mascara (vb 6 - para números de DNI)

Info7/10/2012

Hola a todos, he visto que le vb 6, no tiene una opción especifica como tienen las celdas de una hoja de calculo, donde uno le puede dar la mascara, es decir, como quiero que ingrese los datos, y no estoy hablando del formato que el texbox de vb 6, si lo tiene. Luego de mucho pensar y buscar termine programando un textbox con mascara, al menos eso es en apariencia aunque sea el mismo texto nada mas que muy programado.

Bueno acá el código, si tiene algún problema comenten


Dim Uso As Integer

Private Sub Form_Load()
Uso = 0
End Sub

Private Sub Text1_Change()

If Uso = 0 Then
If Len(Text1) = 1 Then
Text1.Text = Text1.Text & "0.000.000"
Text1.SelStart = Len(Text1)
Text1 = FormatNumber(Text1, 0)
Text1.SelStart = 1
Text1.SelLength = Len(Text1) - 1
End If

If Len(Text1) = 2 Then
Text1.Text = Text1.Text & ".000.000"
Text1.SelStart = Len(Text1)
Text1 = FormatNumber(Text1, 0)
Text1.SelStart = 3
Text1.SelLength = Len(Text1) - 3
End If

If Len(Text1) = 4 Then
Text1.Text = Text1.Text & "00.000"
Text1.SelStart = Len(Text1)
Text1 = FormatNumber(Text1, 0)
Text1.SelStart = 4
Text1.SelLength = Len(Text1) - 4
End If

If Len(Text1) = 5 Then
Text1.Text = Text1.Text & "0.000"
Text1.SelStart = Len(Text1)
Text1 = FormatNumber(Text1, 0)
Text1.SelStart = 5
Text1.SelLength = Len(Text1) - 5
End If

If Len(Text1) = 6 Then
Text1.Text = Text1.Text & ".000"
Text1.SelStart = Len(Text1)
Text1 = FormatNumber(Text1, 0)
Text1.SelStart = 7
Text1.SelLength = Len(Text1) - 6
End If

If Len(Text1) = 8 Then
Text1.Text = Text1.Text & "00"
Text1.SelStart = Len(Text1)
Text1 = FormatNumber(Text1, 0)
Text1.SelStart = 8
Text1.SelLength = Len(Text1) - 8
End If

If Len(Text1) = 9 Then
Text1.Text = Text1.Text & "0"
Text1.SelStart = Len(Text1)
Text1 = FormatNumber(Text1, 0)
Text1.SelStart = 9
Text1.SelLength = Len(Text1) - 9
End If
End If

End Sub

Private Sub Text1_GotFocus()
Text1.SelLength = Len(Text1)
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)

If KeyAscii = 46 Or KeyAscii = 8 Then
Uso = 1
Else
Uso = 0
End If

End Sub


Disfruten, compartir es la solución.-
Datos archivados del Taringa! original
10puntos
0visitas
0comentarios
Actividad nueva en Posteamelo
0puntos
2visitas
0comentarios
Dar puntos:

Dejá tu comentario

0/2000

Autor del Post

m
morkcop🇦🇷
Usuario
Puntos0
Posts10
Ver perfil →
PosteameloArchivo Histórico de Taringa! (2004-2017). Preservando la inteligencia colectiva de la internet hispanohablante.

CONTACTO

18 de Septiembre 455, Casilla 52

Chillán, Región de Ñuble, Chile

Solo correo postal

© 2026 Posteamelo.com. No afiliado con Taringa! ni sus sucesores.

Contenido preservado con fines históricos y culturales.