3 Replies - 439 Views - Last Post: 29 November 2012 - 08:01 AM Rate Topic: -----

#1 KratosGodOfWar  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 27-November 12

I need to write a collection to a file and read it to the app on load

Posted 27 November 2012 - 10:24 AM

Attached File  Student Collectionss.zip (107.59K)
Number of downloads: 18im also going to attach the Program with this so if any wants to look at it can.
  ' when this code executes on the exit form click event it is supposed to write the entire collection to a txtfile
    'it writes the first file for every item in the collection. I've been hacking away at for about 3 weeks.
    Private Sub btnExit_Click(sender As System.Object, e As System.EventArgs) Handles btnExit.Click
        Dim sDatafile As StreamWriter

        Try
            'open the file
            sDatafile = File.AppendText("StudentData.txt")

            For Each student As Student In studentCollection
                'write student data to the file.

                sDatafile.WriteLine(student.LastName)
                sDatafile.WriteLine(student.FirstName)
                sDatafile.WriteLine(student.IdNumber)
                sDatafile.WriteLine(student.TestAverage)
                sDatafile.WriteLine(student.Grade)

            Next
            sDatafile.Close()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
        Me.Close()
    End Sub


 'Reads the student collection in StudentData.txt file when the form loads 
    'It will place all data in the correct labels and list box. on the main form.[/color]   
    Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim objStudent As New Student
        Dim StudentFile As StreamReader
        StudentFile = File.OpenText("studentData.txt")
        Do Until StudentFile.Peek = -1
            objStudent.LastName = StudentFile.ReadLine
            objStudent.FirstName = StudentFile.ReadLine
            objStudent.IdNumber = StudentFile.ReadLine
            objStudent.TestAverage = CDbl(StudentFile.ReadLine)
            StudentFile.ReadLine()
            AddRecord(objStudent)

        Loop
        UpdateListBox()
    End Sub



Is This A Good Question/Topic? 0
  • +

Replies To: I need to write a collection to a file and read it to the app on load

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9579
  • View blog
  • Posts: 36,290
  • Joined: 12-June 08

Re: I need to write a collection to a file and read it to the app on load

Posted 27 November 2012 - 10:27 AM

Did you forget to post your question?
Was This Post Helpful? 1
  • +
  • -

#3 KratosGodOfWar  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 27-November 12

Re: I need to write a collection to a file and read it to the app on load

Posted 29 November 2012 - 06:33 AM

how do i get it to loop through the items in collection and copy each item not the first item for each item in the collection and write it to a file at time of exiting the program. I also need to be able to read from the file back into the collection then to the the labels and list box of the form.
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9579
  • View blog
  • Posts: 36,290
  • Joined: 12-June 08

Re: I need to write a collection to a file and read it to the app on load

Posted 29 November 2012 - 08:01 AM

Quote

copy each item not the first item for each item

I don't know what this means.

Quote

write it to a file

Stream writer! (but you are already doing that)


Quote

read from the file

Stream reader! (but you are already doing that)

... you appear to be doing all of this except for setting labels..
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1