Results 1 to 3 of 3

Thread: Simple problem... 4-column CSV file -> VB 4-column Array

Threaded View

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2006
    Posts
    31

    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
    Last edited by gabba; Nov 14th, 2006 at 08:03 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width