Re: Which is the best method
Theoretically, it would be faster to read it into an array first, because the whole set of integers would be spun up into in-process memory and wouldn't haven't to read from the HardDrive each line. However, most likely your text file is so small that once it reads the first line, Windows will hold the rest in your OS memory anyway so it really wouldn't make a difference. Why don't you test it?
Automate the thing so that the whole process is wrapped in a For Next loop with time stamps like this.
VB Code:
Private Sub TheProcess()
Dim StartTime As DateTime
Dim DoneTime As DateTime
Dim Reps As Integer = 500
Dim x As Integer
StartTime = Now
For x = 0 To Reps
'Your Code here
Next
DoneTime = Now
MsgBox(DateDiff(DateInterval.Second, StartTime, DoneTime).ToString)
End Sub
The MessageBox at the end would show how many seconds to complete 500 (or however many) repetitions.
You could build one of these procedures for both methods and see if one takes longer.
Re: Which is the best method
I'm not sure exactly how you have structures your file but I, personally, would read everything in at once (then close the file), then interpret the data from memory and draw the rects as needed. That would be much faster becasuse the (slow) read operation doesn't have to yield to the (faster) drawing ops.
It would probably be worthwhile re-thinking your file format too (unless you are stuck with what you've got).
Re: Which is the best method
Thanks for the help. That's an excellent idea Kent, I used the code you posted and found that reading everything and then drawing it was significantly faster, as you guys had said. Thanks again!