Public Class Form4

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    ListBox1.Items.Add(InputBox("Masukkan jenama baru anda:"))
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    Dim s As New IO.StreamWriter("toner.dbo")
    For i As Integer = 0 To ListBox1.Items.Count - 1
        s.Write(ListBox1.Items(i) & vbNewLine)
    Next
    s.Close()

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    If IO.File.Exists("toner.dbo") Then
        Dim r As New IO.StreamWriter("toner.dbo")
        Dim txt As New TextBox
        txt.Text = r.ReadToEnd

        ListBox1.Items.Clear()
        For i As Integer = 0 To txt.Lines.Count - 2
            ListBox1.Items.Add(txt.Lines(i))
        Next
        r.Close()

    End If
End Sub

End Class

Recommended Answers

All 5 Replies

What kind of database are you trying to add to? Is it MS-SQL, MySQL, Access, etc.? While a database could be a simple text file it usually is something more complex and can not be maintained with basic text I/O. Please provide more details and we'll try to help you.

Please provide with detailed info as Jim has said and also I don't think a program is capable of doing anything after stop debugging what I think you mean is "On Form Exit" which the code placed here are always executed before the program stop debugging or fully terminate or exit.

Also your codes are in a form of a poor programming as you didn't label the buttons accordingly for easy referral (so that we can see that this code is for this without having to read the entire code to see what is it for, and also no comments.

Try also to familiarize your self with those things they event help you easily spot the codes.

sorry for that and i still a newbie in programming so still got a lot of space to improve
by the way, i found a solution already.tq

If you have found solution you need to mark the post as Solved.

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.