Simple problem... 4-column CSV file -> VB 4-column Array
Hi,
I've got a simple question to most... but I've never used multiple-column arrays before (never could learn how to, mind-boggling!), and not really sure how to progress with this... not even sure if I should be using a multi-column array!
The CSV is like this (even with linebreaks):
392,3290,109
310,1900,490
390,1903,300
321,1033,610
and the CSV has 365 lines in it (one for every day of the year).
I am trying to get the data into an array so it also has an index, like this:
Code:
Index, Cost, Units, Time
1, 392, 3290, 109
2, 310, 1900, 490
3, 390, 1903, 300
4, 321, 1033, 610
This is the cost I use for importing the data into the program, and process into the array:
In the FOR loop, I want to 'index' the CSV file..
Code:
Public Sub GetCostTimeRatio()
Dim hFile As Long
Dim LocalFileName As String
Dim CostTimeRatioIndex(0 To 365, 0 To 365, 0 To 365, 0 To 365) As Long
Dim CostTimeRatioString As String
Dim CostTimeRatioLines() As String
Dim n As Long
LocalFileName = "Q:\timeandcost.csv"
hFile = FreeFile
Open LocalFileName For Input As #hFile
CostTimeRatioString = Input$(LOF(hFile), hFile)
Close #hFile
CostTimeRatioLines = Split(CostTimeRatioString, vbCrLf)
For n = 0 To UBound(CostTimeRatioLines)
CostTimeRatioIndex(n,,,) = Split(CostTimeRatioLines(n), ",")
Next
Debug.Print CostTimeRatioLines(UBound(CostTimeRatioLines))
End Sub
But it says 'Can't assign to array' when I call the function, and it itemises the CostTimeRatioIndex as the culprit...
Help.... please...
Many thanks,
Gabba
Re: Simple problem... 4-column CSV file -> VB 4-column Array
you can't use split to a multicolumn or fixed size array, you would need to write the values to the array in a loop
Re: Simple problem... 4-column CSV file -> VB 4-column Array