I have declared a 2 dimensional, 12 row, 2 column array named strVenues(11,1)
in the public section of the form.
The instructor is gone for the week, so I can't ask her any more questions about this project now. It is due next week, and I haven't even gotten the first part of it figured out! Here's what the she said, when I asked her about this project.
"You do not need the inner FOR loop; since you know that there are only two columns, just write directly to those elements; e.g., strVenues(intRow, 0) and strVenues(intRow,1).
Also, you are not separating the data. You are filling the columns with the entire record. The fields in the record have to be separated and stored in their respective columns.
When you do your readline, you are reading the entire record into your variable strVen. The record has more than one field. You've got to use string manipulation to separate the fields and place them in the correct columns in the array.
Same thing with the list box; you only want to list the events and nothing else."
(I have not gotten to the list box part of this assignment yet.)
I did get it to add only the first field in the record, but I cannot figure out how to get it to add all of the records from the file into the array! There are 11 records in the file, "venues.txt":
Toby Keith,C
Chicago,C
Nora Jones,C
Styx,C
Peter Pan,T
Mama Mia,T
Rent,T
Cats,T
David Copperfield,E
Paula Dean Cooking,E
Tractor Pull,E
I don't know why the instructions say to create a 12 row array, when there are 11 records. Could that be the problem? If so, how would I fix it?
I think this is how you put just the first field into the array. Can you tell me where the error(s) is/are in my code?
Expand|Select|Wrap|Line Numbers
- Private Sub readFile() 'reads file into an array
- 'declare variables
- Dim sreReader As IO.StreamReader
- 'open the file
- sreReader = IO.File.OpenText("venues.txt")
- 'read each record into the array until the array is filled
- Dim strVen As String, intIndex, intCount As Integer
- For intCount = 0 To 10
- strVen = sreReader.ReadLine()
- strVenues(intCount, 0) = strVen.Substring(0, strVen.IndexOf(","))
- intIndex = strVen.IndexOf(",") + 1
- strVenues(intCount, 1) = strVen.Substring(intIndex)
- Next intCount
- sreReader.Close()
I have tried for hours and hours, to figure this out! I watched the class lectures, studied the book and searched online, and tried different things with the code, but nothing works!!! Please help me figure this out!
Could it have something to do with the way I have used the intIndex and substring methods?
Any clue as to what I'm doing wrong will be most appreciated!
Thanks