lundi 6 avril 2015

Reading and Writing Data to Sequential Access Text File

Vote count:


I have an assignment to create a program in Microsoft Visual Studio Express 2012 that opens up a text file that we create and reads a list of names already in it. The program is supposed to take the names and stores them in an array of strings, then display them into a list box. There is also a text box to add a name to an array, when the program closes the program should save the list of names in the array. My main questions are as follows:

  1. How to get the list of names from the array to display upon the program launching

  2. How to add the name from the text box to the already existing array

  3. How to take the array (with the new name in tow) and save it to the file?

It is an online class, the instructor never emails back and we do not have a text book, I have looked around on the web for a while, so I am coming here to see what I can find out.

Here is what I have so far:

Question 1:

Public Class Form1
Dim strReader As System.IO.StreamReader

Private Sub lstNames_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lstNames.SelectedIndexChanged
strReader = New IO.StreamReader("Names.txt")
While (strReader.Peek() > -1)
End While
Dim nameArray() As String = lstNames.Items.OfType(Of String)().ToArray()
End Sub

Question 2: I do not even know where to begin

Question 3:

Private Sub saveExit_Click(sender As Object, e As EventArgs) Handles saveExit.Click
Dim strWriter As New IO.StreamWriter("Names.txt")
End Sub

Right now the writer will just save over the text file with nothing, as at the moment I haven't been able to get the name array loaded into the list box on start up. Thanks to everyone who comments, I appreciate the help!

asked 2 mins ago

Reading and Writing Data to Sequential Access Text File

Aucun commentaire:

Enregistrer un commentaire