Click here to Skip to main content
15,887,344 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionUsing CSV File As Data Reference Pin
Codemonkey854-Sep-08 5:10
Codemonkey854-Sep-08 5:10 
Okay, so I'm trying to make a program that refers to a table of prices for various items. The problem I am having is being able to easily retrieve data from the CSV file... I can read from it, but I want to store it to an easy-to-use lookup table so that I can pull whatever kind of information I want at any given time.

To test this, I tried to make a program that consists only of a listbox, which upon loading of said program would be populated with the names of all of our items. But so far, I cannot figure out how to store this data.

I tried using a multidimensional string array, but for some reason my code isn't working. It seems like the program gets to a certain point in my code and stops doing what it's supposed to do, and the functions end and I'm staring at my form.

Can anyone help me with this? I would really appreciate it!

Imports System.IO
Imports System.Data.OleDb

Public Class Form1

    Dim ITEM_FILE_PATH As String = ""
    Dim ITEM_FILE As String = ""
    Dim ITEM_LIST As String(,)
    Dim ITEM_LINE As String()
    Dim fs As FileStream
    Dim sR As StreamReader
    Dim frstComma As Integer = 0
    Dim thisLine As String = ""
    Dim NumLines As Integer = 0

    Private Sub ReadCSVFile()
        ITEM_FILE_PATH = Application.StartupPath & "\All_Item_Prices.csv"

        fs = New FileStream(ITEM_FILE_PATH, FileMode.Open)
        sR = New StreamReader(fs)

        sR.ReadLine()
        'ITEM_FILE = sR.ReadToEnd

        While sR.EndOfStream = False

            thisLine = sR.ReadLine
            NumLines += 1
            'MsgBox(thisLine)
            frstComma = InStr(thisLine, ",")
            thisLine = thisLine.Substring(frstComma, thisLine.Length - frstComma)
            frstComma = InStr(thisLine, ",")
            thisLine = thisLine.Substring(frstComma, thisLine.Length - frstComma)
            frstComma = InStr(thisLine, ",")
            thisLine = thisLine.Substring(frstComma, thisLine.Length - frstComma)
            'MsgBox(thisLine)
            Dim COMMAS As String = ",,"
            For i As Integer = 2 To 6
                'MsgBox(COMMAS)
                thisLine = Replace(thisLine, COMMAS, "")
                'MsgBox(thisLine)
                COMMAS &= ","
            Next
            'ITEM_FILE &= thisLine & vbNewLine
            'For iC As Integer = 0 To thisLine.Split(",").Count
            '    ITEM_LINE(iC) = thisLine.Split(",")(iC)
            'Next
            MsgBox(thisLine)
            MsgBox(thisLine.Split(",").Count)
            For iC As Integer = 0 To thisLine.Split(",").Count
                ITEM_LIST(iC, NumLines) = thisLine.Split(",")(iC)
                MsgBox(ITEM_LIST(iC, NumLines))
            Next

        End While

        sR.Close()
        fs.Close()

        'MsgBox(ITEM_FILE)

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        ReadCSVFile()

        For iCount As Integer = 0 To NumLines

            MsgBox(iCount)
            MsgBox(ITEM_LIST(0, iCount))

        Next

    End Sub

End Class


Any help? Thanks in advance!

As I sit here, I contemplate the last words of Socrates: "I drank what?".

Pokémon Pearl Friend Code: 4554-2418-6836

AnswerRe: Using CSV File As Data Reference Pin
Steven J Jowett4-Sep-08 12:55
Steven J Jowett4-Sep-08 12:55 
AnswerRe: Using CSV File As Data Reference Pin
Mycroft Holmes4-Sep-08 15:22
professionalMycroft Holmes4-Sep-08 15:22 
GeneralRe: Using CSV File As Data Reference Pin
Codemonkey855-Sep-08 8:19
Codemonkey855-Sep-08 8:19 
GeneralRe: Using CSV File As Data Reference Pin
Mycroft Holmes5-Sep-08 13:32
professionalMycroft Holmes5-Sep-08 13:32 
GeneralRe: Using CSV File As Data Reference Pin
Codemonkey855-Sep-08 19:20
Codemonkey855-Sep-08 19:20 
GeneralRe: Using CSV File As Data Reference Pin
Mycroft Holmes5-Sep-08 22:43
professionalMycroft Holmes5-Sep-08 22:43 
GeneralRe: Using CSV File As Data Reference Pin
Codemonkey856-Sep-08 1:54
Codemonkey856-Sep-08 1:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.