Question Using fileopen to build data array from text files with mulitple lines to listbox

Coop

New member
Joined
Dec 4, 2012
Messages
4
Programming Experience
Beginner
I'm making a program that reads data from a large amount of files into a data array with fileopen for a music and movie store front, with multiple cmb boxes for different categories to filter the files to the listbox. When a listbox item is selected it outputs a description, price and picture of the selected item to a pic and rtb. When I filter the list using my cmb boxes it properly changes the list, but when a new file is selected in the lstbox the previous pictures and descriptions from the original list show up. Something is wrong with the way I'm doing my data arrays and it's messing up the lstbox indexing. Can any of your expertice help me out? My final project is due this Friday. I'm attached a zipped folder of my project.

I added some additonal code and some stuff is commented out.
Thanks
 
Last edited by a moderator:

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,458
Location
Sydney, Australia
Programming Experience
10+
First things first, I have removed your attachment because it contained binaries, which is not allowed. If you want to zip a project for attaching then please make sure that you delete the 'bin' and 'obj' folders first.

Secondly, I for one will not be downloading anyone's project except as a last resort. Your first option should always be to post the relevant code and ONLY the relevant code directly in your post inside formatting tags so it can be easily read without having to do anything or go anywhere. If the issue can't discerned from that, then it MIGHT require a full project.
 

Coop

New member
Joined
Dec 4, 2012
Messages
4
Programming Experience
Beginner
    '---------------------------------------------------------------------
    'Description: Declares total number of files to be read and the path
    '   of where the files are located. 
    '----------------------------------------------------------------------
    Dim cintNumberFiles As Integer = 130
    Dim cintBeginingFile(cintNumberFiles) As Integer
    Dim cstrFileSource As String = "..\GoodFils\"

    '-----------------------------------------------------------------------=--
    'Description: Declares variables for all lines of data from the text files
    '   to be read into which will be used for searching and categorizing
    '   data with other sub routines. 
    '--------------------------------------------------------------------------
    Dim cstrFileName(cintNumberFiles) As String
    Dim cintFileLines(cintNumberFiles) As Integer
    Dim cstrMovieOrCD(cintNumberFiles) As String
    Dim cstrCategory(cintNumberFiles) As String
    Dim cstrItemName(cintNumberFiles) As String
    Dim cstrMedia(cintNumberFiles) As String
    Dim cstrDescription(cintNumberFiles) As String
    Dim cdblPrice(cintNumberFiles) As Double
    Dim cstrPicture(cintNumberFiles) As String

Private Sub frmHolidayStore_Load(sender As System.Object, e _
        As System.EventArgs) Handles MyBase.Load
        Dim strTemp As String = ""
        Dim intFiles As Integer
        Dim i As Integer
        Dim j As Integer

        '----------------------------------------------------------------------
        'Description: Reads list.mmf and assigns a numerical value to each 
        '   file to be further individually read and have the data imported
        '   into variables. 
        '----------------------------------------------------------------------
        FileOpen(1, cstrFileSource & "list.mmf", OpenMode.Input)
        Input(1, strTemp) 'Takes first line of file and saves to strTemp (86)
        intFiles = CInt(strTemp)
        For i = 0 To intFiles - 2 'Gives the amount of files to be read (85)
            Input(1, strTemp)
            cstrFileName(i) = strTemp
        Next i
        FileClose(1)
        For i = 0 To intFiles - 2
            FileOpen(1, cstrFileSource & cstrFileName(i), OpenMode.Input)
            Input(1, strTemp)
            cintFileLines(i) = CInt(strTemp)
            Input(1, cstrMovieOrCD(i))
            Input(1, cstrCategory(i))
            strTemp = LineInput(1)
            cstrItemName(i) = strTemp
            Input(1, strTemp)
            Input(1, cstrMedia(i))
            Input(1, strTemp)
            For j = 7 To cintFileLines(i) - 4
                strTemp = LineInput(1)
                cstrDescription(i) &= strTemp
            Next j
            Input(1, strTemp)
            Input(1, strTemp)
            cdblPrice(i) = Val(strTemp)
            Input(1, cstrPicture(i))
            FileClose(1)
        Next i
        Call DefaultList()
    End Sub

    Private Sub DefaultList()
        '----------------------------------------------------------------------
        'Description: Displays all files to the items list box.
        'Routines calling: The form load calls this Sub to display all itmes on
        '   startup
        '----------------------------------------------------------------------
        Dim i As Integer
        Dim j As Integer
        For i = 0 To cintNumberFiles - 1
            lstItems.Items.Add(cstrItemName(i) & ", $" & cdblPrice(i))
            cintBeginingFile(j) = i
            j += 1
        Next i
        Call UpdateTotals()
    End Sub

    Private Sub cmbMovieFilter_SelectedIndexChanged(sender _
        As System.Object, e As System.EventArgs) Handles _
        cmbMovieFilter.SelectedIndexChanged
        '----------------------------------------------------------------------
        'Description: When index is selected from the cmbMovieFilter, the index 
        '   selected filters the items for a specific Movie category displayed
        '   to lstItems
        '----------------------------------------------------------------------
        'Select Case cmbMovieFilter.SelectedIndex
        '    Case 0
        '        lstItems.Items.Clear()
        '        Call DefaultList()
        '        Call UpdateTotals()
        '        'Case 1
        '        '    ' Need to figure out how to make function work to display all movie
        '        '    'categories.
        '        '    lstItems.Items.Clear()
        '        '    Call UpdateTotals()
        '    Case 2
        '        lstItems.Items.Clear()
        '        Call sItemFilter(cstrCategory, "Action/Adventure")
        '        Call UpdateTotals()
        '    Case 3
        '        lstItems.Items.Clear()
        '        Call sItemFilter(cstrCategory, "Animated")
        '        Call UpdateTotals()
        '    Case 4
        '        lstItems.Items.Clear()
        '        Call sItemFilter(cstrCategory, "Comedy")
        '        Call UpdateTotals()
        '    Case 5
        '        lstItems.Items.Clear()
        '        Call sItemFilter(cstrCategory, "Family / Kids")
        '        Call UpdateTotals()
        '    Case 6
        '        lstItems.Items.Clear()
        '        Call sItemFilter(cstrCategory, "Sci Fi")
        '        Call UpdateTotals()
        'End Select
        cmbMusicFilter.SelectedIndex = -1
        cmbMedia.SelectedIndex = -1
    End Sub
'Private Sub sItemFilter(ByVal cstrItemData() As String, _
    '    ByVal cstrFilterName As String)
    '    '----------------------------------------------------------------------
    '    'Description: Creates a funtion that filters items.
    '    'Called by: cmbMovieFilter, cmbMusicFilter, cmbMedia
    '    '----------------------------------------------------------------------
    '    Dim i As Integer
    '    Dim j As Integer
    '    For i = 0 To cintNumberFiles - 1
    '        If cstrItemData(i) = cstrFilterName Then
    '            cintBeginingFile(j) = i
    '            j += 1
    '        End If
    '    Next i
    '    For i = 0 To j - 1
    '        lstItems.Items.Add(cstrItemName(i) & ", $" & CStr(cdblPrice(i)))
    '    Next
    'End Sub
 
Last edited by a moderator:

Coop

New member
Joined
Dec 4, 2012
Messages
4
Programming Experience
Beginner
This is my first big project and supposed to be on team of four, but three other team mates have no clue so I'm stuck finishing this by myself. Any help would be appreciated. The filter from the cmb boxes is not working properly and I also have no idea how to get the indexing to work for adding items from one list to another while still holding their arrays.

Sorry about the formatting, cut and paste didn't hold formatting.
 

Coop

New member
Joined
Dec 4, 2012
Messages
4
Programming Experience
Beginner
Thanks a lot, I'll pay more attention, just getting used to this forum. Very professional looking forum I must say.
 
Top Bottom