[SOLUCIONADO] Permitir solo una coma en un textbox

(1/1)

Eleкtro:
Estoy intentando que el textbox sólamente acepte números, y una coma (sólamente una coma),
No se que estoy haciendo mal (Acepta más de una coma).

Código
   Private Sub TextBox_Custom_Size_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox_Custom_Size.KeyPress
       e.Handled = NumericOnly(e.KeyChar)
   End Sub
 
   Public Function NumericOnly(ByVal eChar As Char) As Boolean
       Dim chkStr As String = "0123456789,"
       If chkStr.IndexOf(eChar) > -1 OrElse eChar = vbBack Then
           If eChar = Keys.Oemcomma & TextBox_Custom_Size.Text.Contains(",") Then Return True
           Return False
       Else
           Return True
       End If
   End Function

Saludos!

Danyfirex:

Creo que así funcionaria.

Código
Private Sub TextBox_Custom_Size_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox_Custom_Size.KeyPress
       e.Handled = NumericOnly(e.KeyChar)
   End Sub
 
   Public Function NumericOnly(ByVal eChar As Char) As Boolean
        Dim chkStr As String = "0123456789,"
       If chkStr.IndexOf(eChar) > -1 OrElse eChar = vbBack Then
           If eChar = Chr(44) And TextBox1.Text.Contains(",") Then Return True
           Return False
       Else
           Return True
       End If
   End Function

saludos

Eleкtro:
Cita de: Danyfirex en 15 Enero 2013, 16:32 pm

Creo que así funcionaria.


Gracias, pero no :(

Danyfirex:
Cita de: EleKtro H@cker en 15 Enero 2013, 16:39 pm

Gracias, pero no :(


seguro ?

a mi me funciona:S

cambiaste el nombre a tu textbox correspondiente?

Código
  If eChar = Chr(44) And TextBox_Custom_Size.Text.Contains(",") Then Return True

Eleкtro:
Ups, acabo de copiar tu code tál cual y si que funciona, algo habré puesto mal en mi code xD

Solucionado, gracias de nuevo.

Navegación

[0] Índice de Mensajes