Ver Mensaje Individual
  #3 (permalink)  
Antiguo 18/05/2010, 12:10
Avatar de lokoman
lokoman
 
Fecha de Ingreso: septiembre-2009
Mensajes: 502
Antigüedad: 15 años, 7 meses
Puntos: 47
Respuesta: Chequeo de parentesis

Hola!!!

Yo lo hice de esta forma, ademas solo acepta numeros en el textbox:

Código vb:
Ver original
  1. Public Cont As Double
  2.  
  3. Private Sub Command1_Click()
  4.     MsgBox "Faltan " & Cont & " parentesis"
  5. End Sub
  6.  
  7. Private Sub Text1_Change()
  8.     If Text1.Text = Empty Then Cont = 0
  9. End Sub
  10.  
  11. Private Sub Text1_KeyPress(KeyAscii As Integer)
  12.     If Not KeyAscii = 40 Then 'KEYASCII=40 ES (
  13.        If Not KeyAscii = 41 Then 'KEYASCII=41 ES )
  14.            If Not KeyAscii = 8 Then 'KEYASCII=8 ES BACKSPACE
  15.                If KeyAscii < Asc("0") Or KeyAscii > Asc("9") Then
  16.                     KeyAscii = 0
  17.                 End If
  18.             End If
  19.         End If
  20.     End If
  21.    
  22.     If KeyAscii = 40 Then Cont = Cont + 1
  23.    
  24.     If Cont = 0 Then
  25.         If KeyAscii = 41 Then
  26.             KeyAscii = 0
  27.             MsgBox "Falta un '('"
  28.             Exit Sub
  29.         End If
  30.     Else
  31.         If Not KeyAscii = 40 Then 'KEYASCII=40 ES (
  32.            If Not KeyAscii = 41 Then 'KEYASCII=41 ES )
  33.                If Not KeyAscii = 8 Then 'KEYASCII=8 ES BACKSPACE
  34.                    If KeyAscii < Asc("0") Or KeyAscii > Asc("9") Then
  35.                         KeyAscii = 0
  36.                     End If
  37.                 End If
  38.             Else
  39.                 Cont = Cont - 1
  40.                 If Cont < 0 Then MsgBox "Faltan " & Abs(Cont) & " parentesis"
  41.             End If
  42.         End If
  43.     End If
  44. End Sub