The Doctor
New member
Ok i am making a project in ASP.Net. For this part of the code, all i want to do is read in a CSV text file into a dynamic array. Now it used to work, but now i dunno why it doesnt.
Dim stemp As String
Dim atemp() As String
Dim forename, surname, form, year, username, password As New ArrayList
Dim NoOfAccounts As Integer
FileOpen(1, "Chem-Mystery\StudentLogin.txt", OpenMode.Input)
NoOfAccounts = 0
While Not EOF(1)
stemp = LineInput(1)
atemp = stemp.Split(",")
forename(NoOfAccounts).Add = atemp(0)
surname(NoOfAccounts).Add = atemp(1)
form(NoOfAccounts).Add = atemp(2)
year(NoOfAccounts).Add = atemp(3)
username(NoOfAccounts).Add = atemp(4)
password(NoOfAccounts).Add = atemp(5)
NoOfAccounts = NoOfAccounts + 1
End While
FileClose(1)
It crashes on forename(NoOfAccounts) = atemp(0) when NoOfAccounts = 0, so when the While loop first begins. Also, it is reading the text file correctly, and splitting the 6 fields correctly as well. The error says:
Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
Most Forums have been unhelpful. Can you please Help.
THanks
Dim stemp As String
Dim atemp() As String
Dim forename, surname, form, year, username, password As New ArrayList
Dim NoOfAccounts As Integer
FileOpen(1, "Chem-Mystery\StudentLogin.txt", OpenMode.Input)
NoOfAccounts = 0
While Not EOF(1)
stemp = LineInput(1)
atemp = stemp.Split(",")
forename(NoOfAccounts).Add = atemp(0)
surname(NoOfAccounts).Add = atemp(1)
form(NoOfAccounts).Add = atemp(2)
year(NoOfAccounts).Add = atemp(3)
username(NoOfAccounts).Add = atemp(4)
password(NoOfAccounts).Add = atemp(5)
NoOfAccounts = NoOfAccounts + 1
End While
FileClose(1)
It crashes on forename(NoOfAccounts) = atemp(0) when NoOfAccounts = 0, so when the While loop first begins. Also, it is reading the text file correctly, and splitting the 6 fields correctly as well. The error says:
Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
Most Forums have been unhelpful. Can you please Help.
THanks