Patrick B. answered 06/15/19
Math and computer tutor/teacher
In order to allocate the array you have to know how many records there are in advance.
otherwise, on each iteration through your loop you will have to do
REDIM PRESERVE
which keeps the data in array while at the same time allows you to dynamically
allocate it for the next one...
You can put the number of team names as the first item in the file.
Then based on that number, allocate the array, then process it.
Secondly, if the only field is the team name, why not just use an array of strings?
It is just too cumbersome to declare a data structure for just the team name...
Are you sure there not any other fields besides the team name
EX. captain?, # of players, # of wins, # of loses, colors, city, state, zip code, etc.
if it is really a CSV input string, then you read the entire string of team names into
a big input buffer and use the SPLIT function to create the array like this:
Dim inbuff as string
On error goto ERrHandler
FileOpen(1, "filename")
inbuff = LineInput(1)
Dim tokens() as String
tokens = inbuff.split(",")
....
fileclose(1)
============================================
Here is a snippet of code (inside of a button click event) that does what you are asking.
The input file contains:
5
Nickle Valley
Miller Way
Dodge City
Trace Line Park
Clineview
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim inbuff As String
Dim numRecs As Integer
FileOpen(1, "C:\Users\pdiru\Desktop\cities.dat", OpenMode.Input)
inbuff = LineInput(1)
numRecs = Val(inbuff)
Dim teamNames(numRecs) As String
For iLoop = 1 To numRecs
teamNames(iLoop - 1) = LineInput(1)
MsgBox(teamNames(iLoop - 1))
Next
FileClose(1)
End Sub
===================================================