Loop through a csv file... RRS feed

  • Question

  • User-768405968 posted

    I'm trying to create a validation program which entails throwing everything in a csv file that i have into array and then looping through it and doing a comparison.

    Here is some of my preexisting code which currently finds the name of a file that I want to do a comparison off by basically using a InStrRev function ...

    Private Function getFileName(ByVal tProcessDir As String, ByVal tARZ FileName As String) As String

    Dim tXSDName As String

    Dim tSingleLetterCheck As String

    Dim ii As Short

    Dim ii2 As Short

    tXSDName = tXSDFileName

    ii = InStrRev(tXSDName, "_") + 1

    tSingleLetterCheck = VB.LCase(Mid(tXSDName, ii))

    If Len(tSingleLetterCheck) = 1 Then

    ii2 = InStrRev(tXSDName, "_", ii - 2) - 1

    tXSDName = Mid(tXSDName, 1, ii2)

    End If

    ii = InStr(tXSDName, "_ARZ") - 1

    If ii <> -1 Then

    tXSDName = Mid(tXSDName, 1, ii)

    End If

    ii = InStr(tXSDName, "_HIST") - 1

    If ii <> -1 Then

    tXSDName = Mid(tXSDName, 1, ii)

    End If

    ii = InStrRev(tXSDName, "_")

    If Mid(tXSDName, ii) = "_TT" Then

    tXSDName = Mid(tXSDName, 1, ii - 1)

    End If

    Return tARZ

    End Function

    What i would like to do is have this function store everything from my file_names.csv file into an array and just loop through the array to match the appropriate filename to the appropriate file. Hopefully that made sense. Any idea on how to go about this would be appreciated as I've never done anything like this before.

    Tuesday, August 11, 2009 12:07 PM


  • User2130758966 posted

    This looks like old school vb6 code. Are you importing Microsoft.VisualBasic at the top of your page?

    This is an old way to do things.

    If you are developing in asp.net 3.5 environment then you could use LinqToCsv to provide powerful query features that will let you get at the data you want.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, August 11, 2009 4:23 PM