Buiilding a program to search a csv file by partnumber, then recover the info associated with that partnumber

I have a csv file with several partnumbers, descriptions, weight, cost, etc.. I have code to find a particular partnumber but can't figure out how to get the info that goes with that partnumber like cost, weight, etc. Here is the code so far:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim FiletoSearch As String
        FiletoSearch = c:\csvfiles\partnumbers.csv
        Dim Findstring = IO.File.ReadAllText(FiletoSearch)
        Dim wordSearch As String

        wordSearch = TextBox1.Text

        If Findstring.Contains(wordSearch) Then
            MsgBox("Found: " & wordSearch)

        Else
            MsgBox(wordSearch & " Not There")
        End If

    End Sub

Each partnumber, lets say 15133, has a string of data with it and the last value in the string is 15133.jpg. I want to capture all between the partnumber 15133 and the end of all its information at 15133.jpg. How is this done?

Thanks
David WaltersWebsite AdminAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fernando SotoRetiredCommented:
Hi nucomputerguy;

Modified the code to get the results you want.

'' Looking for this part number
Dim FiletoSearch As String
FiletoSearch = "c:\Working Directory\Test.csv"
'' Load the file into a List(Of String), each element in the list is one line in the file
Dim Findstring As List(Of String) = IO.File.ReadAllLines(FiletoSearch).ToList()
'' Search for an item
Dim wordSearch As String

wordSearch = TextBox1.Text
'' When the For Each loop completes this will hold all the columns
'' of the row the wordSearch was found in.
Dim foundLine As New List(Of String)()

'' Find the search word
For Each line As String In Findstring
    If line.Contains(wordSearch) Then
        '' Found the search word and storing it in the list
        foundLine.AddRange(line.Split(New String() {","}, StringSplitOptions.None).ToList())
        '' Exit because we have completed the search and found the word
        Exit For
    End If
Next

If foundLine.Count() = 0 Then
    Console.WriteLine("Part number " & wordSearch & " was not found")
Else
    '' Do what you need to do with the columns of that row
End If

Open in new window

0
David WaltersWebsite AdminAuthor Commented:
I'm missing something. Was wanting to put the found part number and its data in a textbox. Not using console. A windows form application.
0
Fernando SotoRetiredCommented:
That was a Windows Form application I posted note line 9 where the data is coming from.

Console.WriteLine(...) are being used here to test the data to the IDE Output put window. Please remove those lines of code and replace them with what you want to display them at.
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

David WaltersWebsite AdminAuthor Commented:
I'm sorry Mr Soto but I don't know how to replace them with what I want to display them at. I am new to Visual Studio 2013 from VB6. Was hoping to put the found partnumber and its information from its columns in a text string and the text string visible in a textbox.
0
Fernando SotoRetiredCommented:
Try something like this.

If foundLine.Count() = 0 Then
    '' Display not found message to user
Else
     '' the list(Of String) has each of the fields of the csv file. Index zero of the list is the first field of of the line from the csv line. And so on.
     TextBox1.Text = foundLine(0)
     TextBox2.Text = foundLine(1)
      ' continue this till all data is displayed
End If

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
David WaltersWebsite AdminAuthor Commented:
There we go! Thanks for the code. Can take it from here. :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.