Vb.net Index was out of range !

hassen_ben_mbarek Messages postés 3 Statut Membre -  
hassen_ben_mbarek Messages postés 3 Statut Membre -
Bonjour,
j'ai un probleme dans ce code source l'erreur s'affiche aprés que je choisie le fichier a ouvrir :
Imports System.Threading
Imports System.IO

Public Class Form1
Dim opn As OpenFileDialog
Dim sv As SaveFileDialog
Dim str As String
Dim ligne As Integer
Dim file As System.IO.StreamWriter

Dim lst As List(Of String) = New List(Of String)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim th As New Threading.Thread(AddressOf opn_f)

th.SetApartmentState(ApartmentState.STA)
th.Start()
End Sub
Sub opn_f()
opn = New OpenFileDialog
Dim th As New Threading.Thread(AddressOf for_f)
If opn.ShowDialog = Windows.Forms.DialogResult.OK Then
str = opn.FileName
Try
FileOpen(1, str, OpenMode.Input, OpenAccess.Default)
While Not EOF(1)
ligne = Val(LineInput(1))
lst.Add("<p> <a href='http://zone-h.org/archive/ip=" + lst.Item(ligne) + " </p>test</a> </p>")
End While
'file = My.Computer.FileSystem.OpenTextFileWriter("ips.txt", True)
'file.WriteLine("<p> <a href='http://zone-h.org/archive/ip=" + lst.Item(ligne) + " </p>test</a> </p>")
'th.Start()
FileClose(1)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End If
End Sub
Sub for_f()
If Me.InvokeRequired Then
Me.Invoke(New MethodInvoker(AddressOf for_f))
Else
For i As Integer = 0 To lst.Count - 1
ListBox1.Items.Add(lst.Item(i))
Next
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim th As Thread = New Thread(AddressOf save)
th.SetApartmentState(ApartmentState.STA)
th.Start()
End Sub
Sub save()
sv = New SaveFileDialog
If sv.ShowDialog = Windows.Forms.DialogResult.OK Then
Try
FileOpen(1, sv.FileName, OpenMode.Binary, OpenAccess.Default)
For i As Integer = 0 To lst.Count - 1
FilePut(1, lst.Item(i) & vbCrLf)
Next
FileClose(1)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End If
End Sub
End Class

1 réponse

  1. hassen_ben_mbarek Messages postés 3 Statut Membre
     

    Imports System.Threading
    Public Class Form1
    Dim opn As OpenFileDialog
    Dim sv As SaveFileDialog
    Dim str As String
    Dim ligne As String
    Dim lst As List(Of String) = New List(Of String)
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim th As New Threading.Thread(AddressOf opn_f)

    th.SetApartmentState(ApartmentState.STA)
    th.Start()
    End Sub
    Sub opn_f()
    opn = New OpenFileDialog
    Dim th As New Threading.Thread(AddressOf for_f)
    Dim string1 As String = TextBox1.Text
    Dim string2 As String = TextBox2.Text
    If opn.ShowDialog = Windows.Forms.DialogResult.OK Then
    str = opn.FileName

    Try
    FileOpen(1, str, OpenMode.Input, OpenAccess.Default)
    While Not EOF(1)
    ligne = LineInput(1)
    lst.Add(string1 + ligne + string2)
    End While

    th.Start()
    FileClose(1)
    MsgBox("Job Done , Click Save now !")
    Catch ex As Exception
    MsgBox(ex.Message)
    End Try
    End If
    End Sub
    Sub for_f()
    If Me.InvokeRequired Then
    Me.Invoke(New MethodInvoker(AddressOf for_f))
    Else
    For i As Integer = 0 To lst.Count - 1
    ListBox1.Items.Add(lst.Item(i))
    Next
    End If
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    Dim th As Thread = New Thread(AddressOf save)
    th.SetApartmentState(ApartmentState.STA)
    th.Start()
    End Sub
    Sub save()
    sv = New SaveFileDialog
    If sv.ShowDialog = Windows.Forms.DialogResult.OK Then
    Try
    FileOpen(1, sv.FileName, OpenMode.Binary, OpenAccess.Default)
    For i As Integer = 0 To lst.Count - 1
    FilePut(1, lst.Item(i) & vbCrLf)
    Next
    FileClose(1)
    MsgBox("File Saved Successfully")
    Catch ex As Exception
    MsgBox(ex.Message)
    End Try
    End If
    End Sub

    End Class
    image > http://postimg.org/image/6c6j0ytqj/
    0