Visual Basic.NET - Funcion

 
Vista:

Funcion

Publicado por Pablo Ricardo (1 intervención) el 30/06/2012 16:04:21
Hola a todos, necesitaría si me pueden ayudar con esta funcion. Al llamarla desde un TextBox lo que logro es que cuando estoy ingresando un nro. cuando tecleo el punto "." el cursor se posiciona despues del separador decimal, es decir luego de la coma. Funciona correctamente el unico inconveniente es que si tecleo el punto desde el teclado numerico, es decir el que esta entre el cero y el Intro no me funciona. Alguien me podria decir que tendria que modificarle a la funcion para poder lograr esto.

Muchas gracias de antemano y Saludos para todos.

1
2
3
4
5
6
7
8
9
10
11
12
13
Public Function Numeros(ByVal txtControl As TextBox, ByVal caracter As Char, ByVal decimales As Boolean) As Boolean
        If (Char.IsNumber(caracter, 0) = True) Or caracter = Convert.ToChar(8) Or caracter = "." Then
            If caracter = "." Then
                If decimales = True Then
                    If txtControl.Text.IndexOf(".") <> -1 Then Return True
                Else : Return True
                End If
            End If
            Return False
        Else
            Return True
        End If
    End Function
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

Funcion

Publicado por Felix (4 intervenciones) el 14/09/2012 21:54:06
Esta es la rutina con la que trabajo yo.
Elimina lo que no te interese y ya está.

Private Sub TxtImporte_KeyPress ' Con comas
Dim I, Cont As Integer
Cont = 0
If e.KeyChar = ChrW(46) Then
e.KeyChar = ChrW(44)
End If
Select Case AscW(e.KeyChar)
Case 48 To 57
Cont = 0
For I = 1 To Strings.Len(TxtImporte.Text)
If Strings.Mid(TxtImporte.Text, I, 1) = "," Then
Cont = 1
End If
Next I
If Cont = 1 Then
TxtImporte.MaxLength = 15
Else
TxtImporte.MaxLength = 6
End If
Case Is = 8

Case 44
Cont = 0 : TxtImporte.MaxLength = 15
For I = 1 To Strings.Len(TxtImporte.Text)
If Strings.Mid(TxtImporte.Text, I, 1) = "," Then
Cont = Cont + 1
End If
Next I
If Cont > 0 Then
e.KeyChar = Convert.ToChar(0) : Beep()
End If

Case Else
e.KeyChar = Convert.ToChar(0) : Beep()
End Select
End Sub
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar