Results 1 to 14 of 14

Thread: [RESOLVED] Having trouble with Listbox

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2010
    Posts
    13

    Resolved [RESOLVED] Having trouble with Listbox

    Hey guys im working on a small mp3 streaming client and im having trouble getting a listbox to display the .mp3 files in a specific directory on my server. I wanna have this listbox display all the different mp3 tracks in my directory so when the user double clicks the track name in the listbox it will redirect the mediaplayers url to start the stream of the song. So can anyone help me with this thanks in advanced

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Having trouble with Listbox

    vb Code:
    1. mypath = "c:\mp3s\"  'change to suit
    2. fname = dir(mypath & "*.mp3")
    3. do while len(fname) > 0
    4.   list1.additem fname
    5.   fname = dir
    6. loop
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2010
    Posts
    13

    Re: Having trouble with Listbox

    what do i dim mypath,fnam,and dir as?

  4. #4

  5. #5

    Thread Starter
    New Member
    Join Date
    Jul 2010
    Posts
    13

    Re: Having trouble with Listbox

    Quote Originally Posted by FireXtol View Post
    What kind of server is it?
    i have all the .mp3 files hosted on a website. How can i get them to showup in the listvbox?

  6. #6

    Thread Starter
    New Member
    Join Date
    Jul 2010
    Posts
    13

    Re: Having trouble with Listbox

    the server is just a linux VPS.

  7. #7
    Fanatic Member FireXtol's Avatar
    Join Date
    Apr 2010
    Posts
    874

    Re: Having trouble with Listbox

    So you're probably using Apache, basically some HTTP server? Is the directory they're in public?

    You'll need to use something like Inet or Winsock to request the directory contents, then parse the response.

  8. #8

    Thread Starter
    New Member
    Join Date
    Jul 2010
    Posts
    13

    Re: Having trouble with Listbox

    Quote Originally Posted by FireXtol View Post
    So you're probably using Apache, basically some HTTP server? Is the directory they're in public?

    You'll need to use something like Inet or Winsock to request the directory contents, then parse the response.

    yes it is a simple http apache server and there in a public directory i dont have the .htaccess file restricting anything from viewing it.

  9. #9
    Fanatic Member FireXtol's Avatar
    Join Date
    Apr 2010
    Posts
    874

    Re: Having trouble with Listbox

    So how far along are you? Do you need help with the downloading of the directory list from the server, and/or parsing the response?

  10. #10

    Thread Starter
    New Member
    Join Date
    Jul 2010
    Posts
    13

    Re: Having trouble with Listbox

    Quote Originally Posted by FireXtol View Post
    So how far along are you? Do you need help with the downloading of the directory list from the server, and/or parsing the response?
    yes im still trying to figure out that but ive never done that before so i would have no clue were to start from :/

  11. #11
    Fanatic Member FireXtol's Avatar
    Join Date
    Apr 2010
    Posts
    874

    Re: Having trouble with Listbox

    I'd suggest Inet. Goto Components | Controls and check: Microsoft Internet Transfer Control

    Add the control to a form and add some code:
    vb Code:
    1. Dim strDirs As String
    2. strDirs = Inet1.OpenURL(YOUR_URL_HERE)

    Most likely your server will return a list of links. You can use StrFindBetween, for instance, see the link in my sig under Strings. You'll want to find: "<a href=""" to """>", then perform an Instr on the string between those two strings. In the Instr determine if there's a forward slash "/", and if so treat that as a directory, and not a file. If it's a file(and not a directory), then instr for the ".MP3" extension, and if so add it to the list.

    Now, add a List1, and try this:

    vb Code:
    1. Dim strDirs As String, strResult As String
    2. Dim X As Long, Y As Long
    3.  
    4. strDirs = Inet1.OpenURL("some_url_here")
    5.  
    6. X = InStr(strDirs, "<a href=""")
    7. Do While X > 0
    8.   X = X + Len("<a href=""")
    9.   Y = InStr(X, strDirs, """>")
    10.   If X And Y Then
    11.     strResult = LCase$(Mid$(strDirs, X, Y - X))
    12.     If InStr(strResult, "/") Then
    13.       'directory
    14.     ElseIf InStr(strResult, ".mp3") Then
    15.       'mp3 file
    16.       List1.AddItem Mid$(strDirs, X, Y - X) 'names are case sensitive, so re-fetch this
    17.     Else
    18.       'other file
    19.     End If
    20.   Else
    21.     Exit Do 'we're out of string, there are no matches
    22.   End If
    23.   X = InStr(Y, strDirs, "<a href=""")
    24. Loop

  12. #12

    Thread Starter
    New Member
    Join Date
    Jul 2010
    Posts
    13

    Re: Having trouble with Listbox

    its not returning any values into the listbox

  13. #13

    Thread Starter
    New Member
    Join Date
    Jul 2010
    Posts
    13

    Re: Having trouble with Listbox

    oh i got it to work thank you for all your help

  14. #14

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