|
-
May 10th, 2006, 04:54 PM
#1
Thread Starter
Addicted Member
[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
Last edited by lionelnz; May 10th, 2006 at 04:58 PM.
-
May 10th, 2006, 05:30 PM
#2
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.
-
May 10th, 2006, 06:14 PM
#3
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?
My usual boring signature: Nothing
 
-
May 10th, 2006, 06:46 PM
#4
Thread Starter
Addicted Member
Re: Data to an array from TXT file
 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!!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|