[RESOLVED] Data to an array from TXT file
Hi folks. I am trying to sort a list of phone directories stored in a TXT via a bubblesort using a tempArray. The problem I have that the code breaks on the line that supposed to store the data in the array. This part of a bigger exercise but I need to list data alpha/numeric ascending.
VB Code:
Dim sr As StreamReader
Dim sw As StreamWriter
Dim temp() As String
Dim prompt As String
Dim counter, i, j As Integer
fn = "PHONELISTS.TXT" 'File with phone directories
sr = File.OpenText(f & fn)
counter = 0
Do While (sr.Peek <> -1)
counter += 1
:confused: [COLOR=Blue][B]temp(i) = sr.ReadLine [/B] [/COLOR]
Loop
sr.Close()
OpenDir(fn, counter)
End Sub
Re: Data to an array from TXT file
You haven't created an array object. This line:declares an array variable. You cannot create an array object without specifying how many elements it will contain because arrays are fixed-size. Even if you had created an array object you couldn't simply keep adding elements to it beyond its length. I suggest that you follow the Start VB.NET link in my signature and read the section on arrays. You should find that it enlightens you considerably regarding arrays in .NET.
Re: Data to an array from TXT file
You can always resize with something like this:
VB Code:
dim sz as integer
dim arr() as string
sz+=1
redim preserve arr(sz)
arr(sz)="Whatever"
There are other ways, and there may well be simpler ways, but not using a straight array (at least not one that I know of).
So, why bubble sort? With all the options out there, why choose the slowest one?
Re: Data to an array from TXT file
Quote:
Originally Posted by Shaggy Hiker
So, why bubble sort? With all the options out there, why choose the slowest one?
Cheers I do have to do a bubblesort & this is part of a bigger project.
I have to search for & create phone directories(PD) and the phone directories are in a sequential TXT file. If PD not exist then create it then I have to add & delete names to the various directories. All data have to be in ascending alpha order as well.
This is killing me as I think I have system problems, I have trouble getting on the net, I am doing home study & of course the text has minor glitches so I need al the help I can get!!! :eek: