ayuda con error
Publicado por Alvar0 (19 intervenciones) el 22/04/2013 15:17:04
Estoy trabajando con un codigo para validar rut pero tengo un problema, el codigo es el siguiente:
El tema es que al quedar el campo de texto vacio se produce un error y se cae el programa, el error es el siguiente :"La longitud no puede ser inferior a cero.Nombre del parámetro: length" y me marca la linea rutLimpio = rutLimpio.Substring(0, rutLimpio.Length - 1), ojala me puedan ayudar ya que soy nuevo en lo que es vb.net, saludos
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
Private Sub mtxRut_Validated(ByVal sender As Object, ByVal e As System.EventArgs) Handles mtxRut.Validated
Dim rutLimpio As String
Dim digitoVerificador As String
Dim suma As Integer
Dim contador As Integer = 2
rutLimpio = mtxRut.Text.Replace(".", "")
rutLimpio = rutLimpio.Replace("-", "")
rutLimpio = rutLimpio.Replace(" ", "")
rutLimpio = rutLimpio.Substring(0, rutLimpio.Length - 1)
digitoVerificador = mtxRut.Text.Substring(mtxRut.Text.Length - 1, 1)
Dim i As Integer
For i = rutLimpio.Length - 1 To 0 Step -1
If contador > 7 Then
contador = 2
End If
suma += Integer.Parse(rutLimpio(i).ToString()) * contador
contador += 1
Next
Dim dv As Integer = 11 - (suma Mod 11)
Dim DigVer As String = dv.ToString()
If DigVer = "10″ Then" Then
DigVer = "K"
End If
If DigVer = "11″ Then" Then
DigVer = "0″"
End If
If DigVer = digitoVerificador.ToUpper Then
lbRut.Text = "Rut Valido"
txtNombreEmp.Focus()
btIngresarEmp.Enabled = True
Else
lbRut.Text = "Rut Invalido"
MessageBox.Show("Rut Invalido", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
mtxRut.Focus()
mtxRut.SelectAll()
btIngresarEmp.Enabled = False
End If
End Sub
El tema es que al quedar el campo de texto vacio se produce un error y se cae el programa, el error es el siguiente :"La longitud no puede ser inferior a cero.Nombre del parámetro: length" y me marca la linea rutLimpio = rutLimpio.Substring(0, rutLimpio.Length - 1), ojala me puedan ayudar ya que soy nuevo en lo que es vb.net, saludos
Valora esta pregunta


0