altXerror 0 Newbie Poster

ok. i am woking on a web browser for a friend of mine. everything works except for the favourites / history code, which is giving me an Unhandlded access violation.

i have tryed using

Try

but then it gives me a file not found error when attempting to append the files, which are history.hst(History file) and Favourites.dat(favourites)

here is the code:

Public Class Favourites
    Dim SW As IO.StreamWriter
    Dim History As String = "C:\Browzex_Hist.hst"
    Dim Favourites As String = "C:\Browzex_FAV.dat"

    Private Sub Favourites_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Try
            SW = System.IO.File.AppendText(History)
            For a = 1 To ComboBox1.Items.Count
                SW.WriteLine(ComboBox1.Items(a))
                SW.Flush()
            Next
            SW.Close()
            Me.Close()
        Catch ex As Exception

        End Try
    End Sub

    Private Sub Favourites_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        If IO.File.Exists(History) = False Then
            IO.File.Create(History)
        Else
            Load_History()
        End If
        If IO.File.Exists(Favourites) = False Then
                IO.File.Create(Favourites)
        Else

        End If
    End Sub


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Form1.WebBrowser1.Navigate(ComboBox1.Text)
        ComboBox1.Items.Add(ComboBox1.Text)
    End Sub

    Private Sub AddToFavouritesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddToFavouritesToolStripMenuItem.Click
            SW = System.IO.File.AppendText(Favourites)
            SW.WriteLine(ComboBox1.Text)
            SW.Flush()
            SW.Close()
    End Sub

    Private Sub VeiwAllToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VeiwAllToolStripMenuItem.Click
        Form2.Show()
    End Sub

    Friend Sub Load_History()
        Dim Contents As String = History
        Dim FL As Short
        Dim SD As String
        FL = FreeFile()
        FileOpen(FL, Contents, OpenMode.Input)
        While Not EOF(FL)
            SD = LineInput(FL)
            ComboBox1.Items.Add((SD))
        End While
        FileClose(FL)
    End Sub
    Friend Sub Load_Favourites()
        Form2.CheckedListBox1.Items.Clear()
        Dim Contents As String = Favourites
        Dim FL As Short
        Dim SD As String
        FL = FreeFile()
        FileOpen(FL, Contents, OpenMode.Input)
        While Not EOF(FL)
            SD = LineInput(FL)
            Form2.CheckedListBox1.Items.Add((SD))
        End While
        FileClose(FL)
    End Sub
End Class

can you please help me fix this?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.