Thread: hashtables help

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2002
    Posts
    31
    Rep Power
    13

    hashtables help


    hi,
    i am currently writing an audio program in vb 6.
    i want it to be stand alone (no databases).

    i have my music sorted in the following:
    d:\music .....in this directory i have all the artist names
    d:\music\artistname....in this directory i have all the album names
    d:\music\artistname\albumname .....in this directory are the tracks

    currently i am using classes for each of the above, however it is a mess. Should i use a hashtable or some sort of collection object for this.
    i am currently getting the artist, album, track info by iterating through the directories.

    on my search form i have a text field for the search criteria and i want to search on artist name or album name or track name.
    when search is done i am displaying results in a flexgrid and i want the user to be able to click on an indivual track, album (get all tracks in order), or artist(get all albums) and then add to a playlist. which i will then pass to winamp. i've written this in access but attempting to do it in vb is proving to be a little tricky.

    i would also like to sort the flexgrid data alphabetically as in:
    artists, albums, sequencial order for tracks. eg.



    also i have adopted the naming coventions of tracks as in:

    01_the_first_song.mp3
    02_the_second_song.mp3
    03_the_third_song.mp3

    artists and albums the same as far as no spaces, instead using underscores.

    should i use hashtables?
    i need all info to be relational like in a database as in
    artists, albums, tracks tables except staying away from using a database.



    hope this give a fair idea of what i want to achieve.

    any thoughts / suggestions on how i should approach this problem would be greatly appreciated.

    regards,

    aaron.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2002
    Posts
    31
    Rep Power
    13
    also i forgot to mention:
    when i read through the directories and files, they don't contain any spaces, only underscores...and i'm taking the underscore out so it's easier to search.


    for instance i will read the artist directory "Alanis_Morisette"

    and do...

    ClassAlbumsArray(ClassAlbumsArrayLength).SetArtistID(ClassAlbumsArrayLength)


    ClassAlbumsArray(ClassAlbumsArrayLength).SetArtistName("Alanis Morisette")

    ClassAlbumsArray(ClassAlbumsArrayLength).SetPathName(D:\Music\Alanis_Morisette)


    this works fine on my search form when i first load it because i iterate through the ClassAlbumsArray, ClassAlbumsArtistsArray, ClassTracksArray, and fill in the flexgrid. so when i click on a track name i can get the track id because its the reletive row in the flexgrid...however if i do a search on just say..alanis morisette, it won't be correct id cause all records arent' displayed.

    unless i can make an extra column in the datagrid after searching and set it equal to the relevant id for the artist etc....and maybe hide the id column from the user.

    will this help...any ideas anyone?


    the classes ive written work only up until this point where i need to search.

    for instance in a database i would have 3 tables:

    Artists: ArtistID, ArtistName,ArtistPathName, etc

    Albums: ArtistID, AlbumID, AlbumName, AlbumPath, etc

    Tracks: AlbumID, TrackID, TrackName, TrackPath, TrackNumber,etc

    ....or something to that effect...my main problem is getting all the above relational for ease of searching without using a database because i want it to be stand-alone.

    so would i be best using a class for artists, albums & tracks
    and make them a resizable array....and then use hashtables somehow.

    i am quite confused on which avenue to take so any input would be greatly appreciated.

    regards,

    Aaron.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2001
    Location
    Dublin
    Posts
    413
    Rep Power
    14
    I would use a scripting.dictionary from the scripting runtime to store three separate tables of artists, albums and tracks. You may also want to hold a dictionary within each artist object containing a list of the child albums and likewise for the tracks within each album ... depending on how you'll want to use the data in searches etc.

    Using the scripting.filesystemobject to query your drive will also solve your sorting issue as it returns subfolders and files in alphabetical order.

    I have some sample code if you want to have a look through it.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2002
    Posts
    31
    Rep Power
    13
    epl,

    Thankyou very much for your reply, i greatly appreciate it.
    If you could post some sample code for dictionary object in here to give me an idea that would be great.

    ...as far as searching goes, what i'd like to achieve is when my
    search form first opens it will have a list of all music sorted in
    alphabetic order, sorted by artistname, albumname, track order
    in flexgrid so the user can browse through it at their leisure. Or alternatively do a search on artist, albumname, or track name (any combination) and then sort that in the same order in the flexgrid.
    ...then as the user clicks on tracks, albums, or artists append it to the playlist appropriately.

    I was thinking maybe make a temporary array that would hold all the search results, sort of like a result set in a database.
    do you think that is a good way of going about it?


    kindest regards,


    Aaron.
    Last edited by Aaron77; February 20th, 2003 at 09:19 PM.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2001
    Location
    Dublin
    Posts
    413
    Rep Power
    14
    I've tried to attach my sample code - i'll post a link to it if that doesn't work.

    I'm not exactly clear on how you want your search form to work but I guess a temporary array or a collection / dictionary will do the trick for you. You can decide to either populate the array and apply a search routine or else place each item in it's sort order as you add them.

    I guess it would be best to write classes for the all music / artist / album that contain the search routines as member and functions and which return the results in a(n) array / collection / dictionary. Or else just add a boolean flag to the artist / album / track data structure and have it contain whether the most recent include the given item as a result etc... lot's of options.

    You could also package off the music object into an activex object and just call it from within your application for neatness.

    Also MS Media Player 9 does all this - for what it's worth.
    Attached Files
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2001
    Location
    Dublin
    Posts
    413
    Rep Power
    14
    here it is as an activex class... it's not too fast on a large number of files but see what you think
    Attached Files

IMN logo majestic logo threadwatch logo seochat tools logo