Decimales en vb5

Hola a todos.Me gustaría saber como hacer para que en los controles MaskEdBox, en VB5, cuando se pulse el punto de la parte derecha del teclado, actúe como si fuera una coma decimal.Lo he intentado con la promiedad "format #,##0.00" y solo actúa si se pulsa la coma y no el punto. GRACIAS

1 Respuesta

Respuesta
1
La única solución que conozco no involucra un maskedit, sino un textedit común.
Uno puede transformar un textedit en un maskedit con programación.
Para esto tenemos que programar el evento keypress (o keyreleased) y ahí programar lo siguiente:
Si el parámetro key del evento (tecla pulsada) es una tecla que se puede insertar en nuestro textedit (incluyendo el lugar donde lo ingresamos, si es mayúscula, minúscula, etc.) agregamos la tecla o reemplazamos (en el caso del punto reemplazamos por coma), sino dejamos el texto como estaba antes.
Si deseas saber como seria el código exactamente, solo tienes que avisarme y te lo envío.
En la respuesta anterior te explique lo que tenias que hacer, ahora te envío el código:
--- Acá empieza ---
Dim texto_viejo As String
Dim tecla As Integer
Dim posicion As Integer
Dim longitud As Integer
Private Sub Text1_Change()
'Si presiono la tecla delete
If (tecla <> 8 And tecla <> 0) Then
'Solo modifica el texto si ingreso un numero
If (tecla < 48 Or tecla > 57) Then
If (tecla <> 46 And tecla <> 44) Then
Text1.Text = texto_viejo
Label2.Caption = "Debe ingresar un numero, la coma o el punto."
tecla = 0
Text1.SelStart = posicion
Else
If (tecla = 46 Or tecla = 44) Then
If (InStr(1, Text1.Text, ",", vbTextCompare) >= 1) Then
Text1.Text = texto_viejo
Label2.Caption = "No puede ingresar dos veces la coma o el punto."
tecla = 0
Text1.SelStart = posicion
Else
If (Trim(texto_viejo) = "" Or posicion = 0) Then
Label2.Caption = ""
tecla = 0
Text1.Text = "0" & Left(Text1.Text, InStr(1, Text1.Text, ".", vbTextCompare) - 1) & "," & Right(Text1.Text, Len(Text1.Text) - InStr(1, Text1.Text, ".", vbTextCompare))
Else
'Reemplazo punto por coma
Label2.Caption = ""
tecla = 0
Text1.Text = Left(Text1.Text, InStr(1, Text1.Text, ".", vbTextCompare) - 1) & "," & Right(Text1.Text, Len(Text1.Text) - InStr(1, Text1.Text, ".", vbTextCompare))
End If
End If
End If
End If
Else
If (tecla = 48 And Trim(texto_viejo) <> "") Then
'Reemplazo 000,xxx por 0,xxx
If (posicion = 0) Then
Label2.Caption = ""
tecla = 0
Text1.Text = Right(Text1.Text, Len(Text1.Text) - 1)
End If
End If
Label2.Caption = ""
End If
Else
If (longitud > Len(Text1.Text)) Then
Text1.SelStart = posicion - 1
ElseIf (longitud < Len(Text1.Text)) Then
Text1.SelStart = posicion + 1
Else
Text1.SelStart = posicion
End If
Label2.Caption = ""
tecla = 0
End If
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
texto_viejo = Text1.Text
tecla = KeyAscii
posicion = Text1.SelStart
longitud = Len(Text1.Text)
End Sub
--- Acá termina ---
Si quieres que te envíe el proyecto (VB 5), con todos los archivos, simplemente decime cual es tu email.
No te olvides de ponerle puntos a mi respuesta.

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas