Título: [SOLUCIONADO] Permitir solo una coma en un textbox
Publicado por: Eleкtro en 15 Enero 2013, 15:38 pm
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). 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!
Título: Re: Permitir solo una coma en un textbox
Publicado por: Danyfirex en 15 Enero 2013, 16:32 pm
Creo que así funcionaria. 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
Título: Re: Permitir solo una coma en un textbox
Publicado por: Eleкtro en 15 Enero 2013, 16:39 pm
Creo que así funcionaria.
Gracias, pero no :(
Título: Re: Permitir solo una coma en un textbox
Publicado por: Danyfirex en 15 Enero 2013, 16:44 pm
Gracias, pero no :(
seguro ? a mi me funciona:S cambiaste el nombre a tu textbox correspondiente? If eChar = Chr(44) And TextBox_Custom_Size.Text.Contains(",") Then Return True
Título: Re: Permitir solo una coma en un textbox
Publicado por: Eleкtro en 15 Enero 2013, 16:48 pm
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.
|