Error en la funcion
Publicado por Pinky (110 intervenciones) el 22/12/2009 16:31:39
Hola amigos del foro, les comento que estoy trabajando en la parte para verificar el Rut (Chile), este va bien pero cuando llega a la linea que debo comparar si termina en "K" me manda un error de Double, aunque la tenga declarada y si no la tuviera declarada la letra "K", también me manda el mismo error, de todas maneras les adjunto el código que estoy utilizando, ojala que me puedan ayudar.
Function RUT1(ByVal R As String) As Boolean
Dim a1, a2, a3, a4, a5, a6, a7, a8, a9 As Integer
Dim dv, resto, suma, vr As Integer
Dim txtparche As String
txtparche = K
a1 = Val(Mid(R, 1, 1)) * 3
a2 = Val(Mid(R, 2, 1)) * 2
a3 = Val(Mid(R, 4, 1)) * 7
a4 = Val(Mid(R, 5, 1)) * 6
a5 = Val(Mid(R, 6, 1)) * 5
a6 = Val(Mid(R, 8, 1)) * 4
a7 = Val(Mid(R, 9, 1)) * 3
a8 = Val(Mid(R, 10, 1)) * 2
a9 = UCase(Mid(R, 12, 1))
suma = a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8
resto = suma Mod 11
vr = 0
dv = 11 - resto
If (dv = 10 And a9 = txtparche) Or dv = 11 And Val(a9) = 0 Then vr = 1
If Val(a9) = dv Then vr = 1
If vr = 0 Then
MsgBox("El Rut ingresado es incorrecto.", MsgBoxStyle.Critical, "Sistema")
TXTRUT.Text = "__.___.___-_"
TXTRUT.Focus()
Else
MsgBox("El Rut ingresado es correcto.", MsgBoxStyle.Information, "Sistema")
TXTDIRECCION.Focus()
TXTRUT.Enabled = False
End If
End Function
El error se produce en la linea de If (dv=10 and a9=txtparche... etc, favor de ayudarme he tratado de sacar el error y no he podido, desde ya muchas gracias.
Function RUT1(ByVal R As String) As Boolean
Dim a1, a2, a3, a4, a5, a6, a7, a8, a9 As Integer
Dim dv, resto, suma, vr As Integer
Dim txtparche As String
txtparche = K
a1 = Val(Mid(R, 1, 1)) * 3
a2 = Val(Mid(R, 2, 1)) * 2
a3 = Val(Mid(R, 4, 1)) * 7
a4 = Val(Mid(R, 5, 1)) * 6
a5 = Val(Mid(R, 6, 1)) * 5
a6 = Val(Mid(R, 8, 1)) * 4
a7 = Val(Mid(R, 9, 1)) * 3
a8 = Val(Mid(R, 10, 1)) * 2
a9 = UCase(Mid(R, 12, 1))
suma = a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8
resto = suma Mod 11
vr = 0
dv = 11 - resto
If (dv = 10 And a9 = txtparche) Or dv = 11 And Val(a9) = 0 Then vr = 1
If Val(a9) = dv Then vr = 1
If vr = 0 Then
MsgBox("El Rut ingresado es incorrecto.", MsgBoxStyle.Critical, "Sistema")
TXTRUT.Text = "__.___.___-_"
TXTRUT.Focus()
Else
MsgBox("El Rut ingresado es correcto.", MsgBoxStyle.Information, "Sistema")
TXTDIRECCION.Focus()
TXTRUT.Enabled = False
End If
End Function
El error se produce en la linea de If (dv=10 and a9=txtparche... etc, favor de ayudarme he tratado de sacar el error y no he podido, desde ya muchas gracias.
Valora esta pregunta


0