Ver Mensaje Individual
  #2 (permalink)  
Antiguo 31/05/2011, 13:43
SalomonSab
 
Fecha de Ingreso: noviembre-2006
Mensajes: 227
Antigüedad: 17 años, 6 meses
Puntos: 6
Respuesta: limitar textbox caracteres alfanumericos

Haber si te sirve esto:

Código:
Private Sub TxtSD_KeyPress(KeyAscii As Integer)
Dim sDecimal As String
Dim sCar As String * 1
sCar = Chr(KeyAscii)

    'KeyAscii = SoloNumeros(KeyAscii)
     
    If sCar = "." Or sCar = "," Then
        ' comprueba si se ha pulsado coma o punto y lo convierte al
        ' formato del sistema
        KeyAscii = IIf(sDecimal = ",", 44, 46)
        sCar = Chr(KeyAscii)
        ' si ya se ha puesto un punto decimal, no admite otro
        If (InStr(TxtSD, sCar) > 0) Then
             KeyAscii = 0
             Exit Sub
        End If
    ElseIf InStr("0123456789.," & Chr(8), sCar) = 0 Then
        ' sólo admite números, signo negativo, punto, coma y retroceso
        KeyAscii = 0
        Exit Sub
        ' comprueba que el signo menos esté sólo al principio
        ' Nota: Si no queremos negativos, quitar esta condición
    ElseIf sCar = "-" Then
        'If InStr(2, "-", TxtNumeroSalida) = 0 Then
         If TxtSD.SelStart <> 0 Or InStr(TxtSD.Text, "-") > 0 Then
             KeyAscii = 0
        End If
    End If

End Sub
Solo cambia tus valores por los mios y creo que con esto se soluciona tu pedido.

Saludos