Tuesday, November 23, 2010

File Handling (Basic Program)



Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim i As New System.IO.StreamWriter("D:\first_file.doc")
        i.WriteLine("Hello World")
        i.WriteLine("My Name is Maulik")
        i.Close()


    End Sub
   
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        Dim j As New System.IO.StreamWriter("D:\new.ppt")
        j.Write("Maulik A")
        j.WriteLine(" Dave")
        j.WriteLine("Roll No 009")
        j.Close()

    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

        Dim k As New System.IO.StreamReader("D:\new.ppt")
        MsgBox(k.ReadToEnd())


    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

        Dim l As New System.IO.StreamReader("D:\first_file.doc")


        Dim s As String = l.ReadLine()

        Do Until s Is Nothing
            ListBox1.Items.Add(s)
            s = l.ReadLine()
        Loop
        l.Close()

    End Sub
End Class