Ver Mensaje Individual
  #1 (permalink)  
Antiguo 08/08/2013, 21:07
Avatar de gonzalezjesus_77
gonzalezjesus_77
 
Fecha de Ingreso: julio-2013
Ubicación: venezuela
Mensajes: 11
Antigüedad: 10 años, 9 meses
Puntos: 0
Información Manejo Substring con Archivos TXT

Buenas Noches Amigos del Forum.

Tengo archivo Txt que no posee caracteres de separacion, Ya se ha logrado Inserta los Datos en el DataGridView. Cuando la rutina termina de Leer el ultimo dato e Insertarlos en el DataGridView

Me da el siguiente error.

"El índice y la longitud deben hacer referencia a una ubicación en la cadena.
Nombre del parámetro: length"

¿Qué hago que no esta bien?
El codigo es Este:

Código:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Try

            If (TextBox1.Text <> String.Empty) Then
                Dim leer As New StreamReader(TextBox1.Text)
                Dim texto As String = ""
                Dim dat1, dat2, dat3, dat4, dat5, dat6, dat7, dat8, dat9, dat10, dat11, dat12, dat13, dat14, dat15, dat16, dat17, dat18, dat19, dat20, dat21, dat22, dat23 As String
                While (Not texto Is Nothing)
                    texto = leer.ReadLine()
                    If (Not texto Is Nothing) Then
                        dat1 = texto.Substring(0, 2)
                        dat2 = texto.Substring(2, 3)
                        dat3 = texto.Substring(5, 8)
                        dat4 = texto.Substring(13, 1)
                        dat5 = texto.Substring(14, 25)
                        dat6 = texto.Substring(39, 1)
                        dat7 = texto.Substring(40, 3)
                        dat8 = texto.Substring(43, 8)
                        dat9 = texto.Substring(51, 10)
                        dat10 = texto.Substring(61, 1)
                        dat11 = texto.Substring(62, 7)
                        dat12 = texto.Substring(69, 2)
                        dat13 = texto.Substring(71, 1)
                        dat14 = texto.Substring(72, 8)
                        dat15 = texto.Substring(80, 8)
                        dat16 = texto.Substring(88, 2)
                        dat17 = texto.Substring(90, 2)
                        dat18 = texto.Substring(92, 9)
                        dat19 = texto.Substring(101, 2)
                        dat20 = texto.Substring(103, 2)
                        dat21 = texto.Substring(105, 5)
                        dat22 = texto.Substring(110, 6)
                        dat23 = texto.Substring(116, 3)
                        DataGridView1.Rows.Add(dat1, dat2, dat3, dat4, dat5, dat6, dat7, dat8, dat9, dat10, dat11, dat12, dat13, dat14, dat15, dat16, dat17, dat18, dat19, dat20, dat21, dat22, dat23)
                    End If
                End While

            Else
                MsgBox("Seleccione el archivo a cargar", MsgBoxStyle.Exclamation, "Error")
            End If

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub