Results 1 to 7 of 7

Thread: Unresolved Array question

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2001
    Location
    Maumelle, AR
    Posts
    624

    Unresolved Array question

    Ok, here it is broken down. I have this array in my form load event.

    VB Code:
    1. myarray= array("Jim", "Bob", "Sam", "Mike")

    I use a function to read a integer value from a file that corresponds with that index in my array. However, somehow it gets off occasionally.

    Say my function returns 2

    since the first value in an array is 0 then Sam would be an index of 2

    But sometimes when I use:

    VB Code:
    1. text1.text = myarray(2)

    instead of returning Sam it returns Mike

    However, Mike has an index of 3

    What's going on here?

    Also, I am using a For ....Next Loop to loop through a listview getting info on the files and converting the numbers to names .

    This is just an example, my array contains about 128 different names. Any help is appreciated.

    -Jeremy

  2. #2
    Frenzied Member Microbasic's Avatar
    Join Date
    Mar 2001
    Posts
    1,402
    It would be a lot better if you posted some code. Otherwise, just check that the array is never rearranged or the function always returned the right value.


    MicroBasic
    Dragon Shadow Trainer

    There is no good or evil in the world...only programmers and fools .

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2001
    Location
    Maumelle, AR
    Posts
    624

    That's just it

    The function returns the correct # always.

  4. #4
    Frenzied Member Microbasic's Avatar
    Join Date
    Mar 2001
    Posts
    1,402
    OK, but can you post some code? It's much easier for people to debug if you posted code than if you just gave a problem.


    MicroBasic
    Dragon Shadow Trainer

    There is no good or evil in the world...only programmers and fools .

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2001
    Location
    Maumelle, AR
    Posts
    624

    Ok Micro, have at it.....

    Here's the code:

    General Declarations:
    VB Code:
    1. Option Explicit
    2. Public Matrix

    On The Form_Load Event:
    VB Code:
    1. Matrix = Array("Blues", "Classic Rock", "Country", "Dance", "Disco", "Funk", "Grunge", _
    2. "Hip-Hop", "Jazz", "Metal", "New Age", "Oldies", "Other", "Pop", "R&b", "Rap", "Reggae", _
    3. "Rock", "Techno", "Industrial", "Alternative", "Ska", "Death Metal", "Pranks", _
    4. "Soundtrack", "Euro-Techno", "Ambient", "Trip-Hop", "Vocal", "Jazz Funk", "Fusion", _
    5. "Trance", "Classical", "Instrumental", "Acid", "House", "Game", "Sound Clip", "Gospel", _
    6. "Noise", "Alt. Rock", "Bass", "Soul", "Punk", "Space", "Meditative", "Instrumental Pop", _
    7. "Instrumental Rock", "Ethnic", "Gothic", "Darkwave", "Techno-Industrial", "Electronic", _
    8. "Pop-Folk", "Eurodance", "Dream", "Southern Rock", "Comedy", "Cult", "Gangsta", "Top 40", _
    9. "Christian Rap", "Pop/Funk", "Jungle", "Native American", "Cabaret", "New Wave", _
    10. "Psychadelic", "Rave", "Showtunes", "Trailer", "Lo-Fi", "Tribal", "Acid Punk", "Acid Jazz", _
    11. "Polka", "Retro", "Musical", "Rock & Roll", "Hard Rock", "Folk", "Folk/Rock", "National Folk", _
    12. "Swing", "Bebob", "Latin", "Revival", "Celtic", "Bluegrass", "Avantgarde", "Gothic Rock", _
    13. "Progressive Rock", "Psychedelic Rock", "Symphonic Rock", "Slow Rock", "Big Band", "Chorus", _
    14. "Easy Listening", "Acoustic", "Humour", "Speech", "Chanson", "Opera", "Chamber Music", "Sonata", _
    15. "Symphony", "Booty Bass", "Primus", "Porn Groove", "Satire", "Slow Jam", "Club", "Tango", "Samba", _
    16. "Folklore")

    Code When I Populate the Listview Control:
    VB Code:
    1. On Error Resume Next
    2. For X = 0 To File1.ListCount - 1
    3.  
    4.     fname = File1.Path & "\" & File1.List(X)
    5.     'Get the MP3 info
    6.     ReadID3Info fname 'Read Id3v1.1 information
    7.     CMp3info.filename = fname 'Get mp3info such as bitrate
    8.     Set i = ListView1.ListItems.Add(, , File1.List(X))
    9.     i.SubItems(1) = Trim(GetID3.Artist)
    10.     i.SubItems(2) = Trim(GetID3.Songname)
    11.     i.SubItems(3) = Trim(GetID3.Album)
    12.         strTrack = Trim(GetID3.Track)
    13.         If strTrack = 0 Or 32 Then
    14.         strTrack = "-"
    15.         End If
    16.     i.SubItems(4) = strTrack
    17. '------------------------------------------------------------------------------
    18.         tmpGenre = (GetID3.Genre)                 ' <--- Relevant Code
    19.     i.SubItems(5) = Matrix(tmpGenre)
    20. '------------------------------------------------------------------------------
    21.     i.SubItems(6) = Format(FileLen(fname) / 1000000, "#0.00")
    22.     i.SubItems(7) = CMp3info.Frequency
    23.         tmpbitrate = CMp3info.BitRate
    24.     i.SubItems(8) = Left$(tmpbitrate, Len(tmpbitrate) - 3)
    25.         strMins = Format(CMp3info.Duration \ 60, "#0")
    26.         strsecs = Format(CMp3info.Duration Mod 60, "0#")
    27.         strLength = strMins & ":" & strsecs
    28.     i.SubItems(9) = strLength
    29.     i.SubItems(10) = fname
    30. frmBuild.prog1.Value = frmBuild.prog1.Value + 1
    31.     DoEvents
    32. Next

    Any help appreciated.

  6. #6
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,819
    I'm not sure why you're having a problem here, but I think you're doing things in a way that is going to be very difficult to maintain.

    I suggest that you put the matrix items in a text file instead of hard-coding it. That will make your app much more flexible in the future. Read the file into an array when the app loads and go from there.

  7. #7
    New Member
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    15
    No offense but, cafeenman's right. Try other means of storing your data other than the array.

    Anyway, regarding with this part...
    VB Code:
    1. '------------------------------------------------------------------------------
    2.         tmpGenre = (GetID3.Genre)                 ' <--- Relevant Code
    3.     i.SubItems(5) = Matrix(tmpGenre)
    4. '------------------------------------------------------------------------------

    have you checked on tmpGenre's output? Truth is, I also don't find any problems with the results.

    Know first the value of tmpGenre and compare it with your Matrix if the tmpGenre's value corresponds with that of Matrix's
    VB Code:
    1. '------------------------------------------------------------------------------
    2.         tmpGenre = (GetID3.Genre)                 ' <--- Relevant Code
    3.     i.SubItems(5) = Matrix(tmpGenre)
    4.     Debug.Print "tmpGenre=" & tmpGenre & _
    5.         ": Matrix=" & Matrix(tmpGenre)
    6. '------------------------------------------------------------------------------


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width