Asked • 04/24/19

Assigning CSV values to structure?

I'm creating what should be a simple program but I'm having some difficulty assigning values from a file into a structure and it's variables. Visual Basic. Structure: Public Structure Teams Dim teamName As String End Structure Function: Function getAvailableTeams() As Teams() Dim rec As Teams Dim index As Integer Dim recCount As Integer = 0 'Count how many teams exist FileOpen(1, "teamConfig.csv", OpenMode.Input) Do Until EOF(1) LineInput(1) 'Read document line by line recCount += 1 'Increment team count by 1 Loop 'store team names in array Dim teamNames(recCount - 1) As Teams index = 0 Do Until EOF (1) Input(1, rec.teamName) teamNames(index).teamName = rec.teamName index +=1 Loop FileClose(1) Return teamNames End Function Simple subroutine to test values are available and being picked up. Dim availableTeams() As Teams availableTeams = getAvailableTeams() lbltest.text = availableTeams(1).toString The file is stored as a CSV file and there are 11 available team names. team1 \\r\\n team2 \\r\\n etc... I appreciate this is probably something simple but I can't work out where I'm going wrong with this.

1 Expert Answer

By:

Patrick B. answered • 06/15/19

Tutor
4.7 (31)

Math and computer tutor/teacher

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.