Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loop through csv file...

Status
Not open for further replies.

vb89

MIS
Aug 21, 2008
47
US
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 ...
Code:
 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.
 
If I read this correctly, you have a csv file and each line is a list of filenames. You want to get each of these filenames and find the file on your pc. Is that right?

How about something like this.

Code:
[green]' create a streamreader to read through the csv file[/green]
Using inFile As New StreamReader(strFile)

  [green]' read the first line[/green]
  Dim strLine As String = inFile.ReadLine

  [green]' process the current line[/green]
  Do While Not (strLine Is Nothing)

    [green]' split on the commas[/green]
    Dim Current() As String = strLine.Split(",") 

    [green]' loop through the array elements[/green]
    For i As Integer = 0 To Current.Count - 1

      [green][i]' process each filename here[/i][/green]

    Next

    [green]' read the next line[/green]
    strLine As String = inFile.ReadLine
  Loop

  [green]' Close the reader[/green]
  inFile.Close()

End Using
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top