Page 1 of 2 12 LastLast
Results 1 to 40 of 48

Thread: List box question...

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2006
    Posts
    448

    Arrow List box question...

    I am using this code to add files to my listbox:

    CommonDialog1.Flags = cdlOFNAllowMultiselect Or cdlOFNExplorer
    CommonDialog1.Filter = "MP3 (*.mp3)|*.mp3"
    CommonDialog1.ShowOpen
    Dim files As String
    files = CommonDialog1.FileName
    Dim tmp() As String
    tmp = Split(files, Chr(0))
    List4.AddItem tmp(1)
    List4.AddItem tmp(2)

    .. my problem is this code is only allowing 2 files you select ( tmp(1,2) ) .. no more no less.. add to the listbox. How do i change this code to accept however many files are chosen to add to the listbox?
    "Remember, remember the 5th of November, the gun powder treason and plot. I know of no reason why the gun powder treason should ever be forgot."

  2. #2
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: List box question...

    Code:
    CommonDialog1.Flags = cdlOFNAllowMultiselect Or cdlOFNExplorer
    CommonDialog1.Filter = "MP3 (*.mp3)|*.mp3"
    CommonDialog1.ShowOpen
    Dim files As String
    files = CommonDialog1.FileName
    Dim tmp() As String
    tmp = Split(files, Chr(0))
    
    Dim lonLoop as long
    
    for lonloop = 0 ubound(tmp())
        List4.AddItem tmp(lonloop)
    next lonloop

  3. #3
    Lively Member djklocek's Avatar
    Join Date
    Aug 2006
    Posts
    107

    Re: List box question...

    VB Code:
    1. For i = 0 to Ubound(tmp)
    2. List4.AddItem tmp(i)
    3. Next i

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2006
    Posts
    448

    Re: List box question...

    Okay now i got that to work: problem is if i load more than about 6 things then i get ths error: The FileName buffer is too small to store the selected file name(s). (Increase MaxFileSize).

    How do i fix this?
    "Remember, remember the 5th of November, the gun powder treason and plot. I know of no reason why the gun powder treason should ever be forgot."

  5. #5
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: List box question...

    Quote Originally Posted by k0zz
    Okay now i got that to work: problem is if i load more than about 6 things then i get ths error: The FileName buffer is too small to store the selected fie name(s). (Increase MaxFileSize).

    How do i fix this?
    What do you have as the .MaxFileSize property of the common dialog control? The default is 256 bytes. Try setting it to 32767, that's as big as it gets (32 KB).

  6. #6
    Lively Member djklocek's Avatar
    Join Date
    Aug 2006
    Posts
    107

    Re: List box question...

    Hello.
    There is a property of Common Dialog Control named MaxFileSize (default =260). Please change it. Regards

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2006
    Posts
    448

    Re: List box question...

    Okay fixed that with..

    CommonDialog1.MaxFileSize = 32767

    Thanks..
    Now um, I've noticed if there's text in the file name inside of the filelistbox browsing option and you push cancel, what was in the file name box is still added to the listbox. How do i fix this?
    "Remember, remember the 5th of November, the gun powder treason and plot. I know of no reason why the gun powder treason should ever be forgot."

  8. #8
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: List box question...

    Quote Originally Posted by k0zz
    Okay fixed that with..

    CommonDialog1.MaxFileSize = 32767

    Thanks..
    Now um, I've noticed if there's text in the file name inside of the filelistbox browsing option and you push cancel, what was in the file name box is still added to the listbox. How do i fix this?
    Set the .CancelError property to TRUE and add an error handling event:

    Code:
    On Error Goto ErrorHandler
    
    CommonDialog1.CancelError = True
    '...rest of your open file code...
    
    Exit Sub
    
    ErrorHandler:

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2006
    Posts
    448

    Re: List box question...

    Got that to work..using this code now:

    CommonDialog1.Flags = cdlOFNAllowMultiselect Or cdlOFNExplorer
    CommonDialog1.Filter = "MP3 (*.mp3)|*.mp3"
    CommonDialog1.FileName = ""
    CommonDialog1.MaxFileSize = 32767
    If CommonDialog1.CancelError = True Then Exit Sub
    CommonDialog1.ShowOpen
    Dim files As String
    files = CommonDialog1.FileName
    Dim tmp() As String
    tmp = Split(files, Chr(0))
    For i = 0 To UBound(tmp)
    List4.AddItem tmp(i)
    Next i

    Another question.. I noticed that when i add multiple items, when the files reach the listbox they're not in the same order that I selected them in. How can i fix this?
    "Remember, remember the 5th of November, the gun powder treason and plot. I know of no reason why the gun powder treason should ever be forgot."

  10. #10
    Lively Member djklocek's Avatar
    Join Date
    Aug 2006
    Posts
    107

    Re: List box question...

    When you select next file it's automatically coming before the files you selected before. If you want to change it, you have to sort tmp array before listing but sorting depends on you so how do you want to sort it?

  11. #11
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: List box question...

    I think it orders the files itself, I don't know how/why. You could try looping through the array backwards, and see if that works.

    Code:
    For i = UBound(tmp) To 0 Step -1
    List4.AddItem tmp(i)
    Next i

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2006
    Posts
    448

    Re: List box question...

    I want it so that The first item you select is first, the second item you select is second in line, the 3rd item you select is 3rd in line. Just like that.
    "Remember, remember the 5th of November, the gun powder treason and plot. I know of no reason why the gun powder treason should ever be forgot."

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2006
    Posts
    448

    Re: List box question...

    Im selecting the Files in this order..

    First file i select is
    1. Mario Vazquez
    2. Ne-Yo
    3. Akon

    Then when added to the listbox, it shows in this order.
    1. Ne-yo
    2. mario Vazquez
    3. Akon

    just like that.. and thats while using this code :

    For i = UBound(tmp) To 0 Step -1
    List4.AddItem tmp(i)
    Next i
    "Remember, remember the 5th of November, the gun powder treason and plot. I know of no reason why the gun powder treason should ever be forgot."

  14. #14
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: List box question...

    Try adding 10 files and post the order like you just did, so maybe we can see how it's ordering the files.

    It's hard to tell with just 3 files.

  15. #15
    Lively Member djklocek's Avatar
    Join Date
    Aug 2006
    Posts
    107

    Re: List box question...

    Quote Originally Posted by DigiRev
    Try adding 10 files and post the order like you just did, so maybe we can see how it's ordering the files.

    It's hard to tell with just 3 files.
    By the way it's sorting files like this (selected number):

    1st, Last, Last-1, Last-2, ......, 2nd

    So the algorithm will be
    VB Code:
    1. For i = 2 To UBound(tmp)
    2. List1.AddItem tmp(i)
    3. Next i
    4. List1.AddItem tmp(1)

    Assuming that tmp(0) is a path
    Last edited by djklocek; Nov 14th, 2006 at 08:23 PM.

  16. #16

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2006
    Posts
    448

    Re: List box question...

    You got it just right, djklocek... works great now.. thanks.
    "Remember, remember the 5th of November, the gun powder treason and plot. I know of no reason why the gun powder treason should ever be forgot."

  17. #17
    Lively Member djklocek's Avatar
    Join Date
    Aug 2006
    Posts
    107

    Re: List box question...

    No problem man, do not hesitate to rate if you're satisfied
    Regards

  18. #18

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2006
    Posts
    448

    Re: List box question...

    Okay, now i have a "play next" button.... this plays the next song in the song list.. for example. If i have 3 songs, and i push play next, it plays the first one. If i push play next again, it plays the next song in line, and so on... i tried writing this code, but it didn't work:

    Dim intIndex As Integer

    intIndex = List4.ListIndex
    If intIndex = -1 Then List4.ListIndex = 0
    If intIndex > -1 Then intIndex = intIndex + 1

    .. it played the first song, but when i pushed the buttn again, it just started the song right over again.. thanks for any help.
    "Remember, remember the 5th of November, the gun powder treason and plot. I know of no reason why the gun powder treason should ever be forgot."

  19. #19

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2006
    Posts
    448

    Re: List box question...

    Any answers :|
    "Remember, remember the 5th of November, the gun powder treason and plot. I know of no reason why the gun powder treason should ever be forgot."

  20. #20
    Lively Member djklocek's Avatar
    Join Date
    Aug 2006
    Posts
    107

    Re: List box question...

    Please post your button_click code.

  21. #21

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2006
    Posts
    448

    Re: List box question...

    On Error Resume Next


    Dim intIndex As Integer

    intIndex = List4.ListIndex
    If intIndex = -1 Then List4.ListIndex = 0
    If intIndex > -1 Then intIndex = intIndex + 1


    MediaPlayer1.FileName = List4.List(List4.ListIndex)
    MediaPlayer1.Play
    "Remember, remember the 5th of November, the gun powder treason and plot. I know of no reason why the gun powder treason should ever be forgot."

  22. #22
    Lively Member djklocek's Avatar
    Join Date
    Aug 2006
    Posts
    107

    Re: List box question...

    VB Code:
    1. 'In general declarations
    2. Dim Number as Integer
    3.  
    4. Private Sub List4_Click()
    5. Number = List4.ListIndex
    6. End Sub
    7.  
    8. Private Sub Play_Click()
    9. On Error Resume Next
    10.  
    11. MediaPlayer1.FileName = List4.List(Number)
    12. MediaPlayer1.Play
    13. Number = Number + 1
    14. End Sub

    That's not a sophisticated method but maybe it will work for you

  23. #23

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2006
    Posts
    448

    Re: List box question...

    Sorry, but it doesnt work When you load a couple songs in, and u push the play, nothing happens. When you click on one of the songs in the box and it highlights, and then push play, it plays.. but if you push it again, it still doesnt move on to the next item
    "Remember, remember the 5th of November, the gun powder treason and plot. I know of no reason why the gun powder treason should ever be forgot."

  24. #24
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: List box question...

    Ah, good, VBCode is working again.

    Try changing it to this:

    VB Code:
    1. 'In general declarations
    2. Dim Number as Integer
    3.  
    4. Private Sub List4_Click()
    5. Number = List4.ListIndex
    6. End Sub
    7.  
    8. Private Sub Play_Click()
    9. On Error Resume Next
    10.  
    11. If Number > List4.ListCount Then Number = 1 Else Number = Number + 1
    12.  
    13. MediaPlayer1.FileName = List4.List(Number)
    14. MediaPlayer1.Play
    15.  
    16. End Sub

  25. #25

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2006
    Posts
    448

    Re: List box question...

    Ok number 1: It will only play the first song in the list, and is NOT highlighting it. Number 2: if you push next again, nothing happens except the media player stops :|
    "Remember, remember the 5th of November, the gun powder treason and plot. I know of no reason why the gun powder treason should ever be forgot."

  26. #26
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: List box question...

    It's hard to test without VB on this computer...try this...

    VB Code:
    1. 'General declarations
    2. Dim Number As Integer
    3.  
    4. Private Sub Play_Click()
    5.     If Number = 0 Then Number = 1
    6.  
    7.     MediaPlayer1.FileName = List4.List(Number-1)
    8.     MediaPlayer1.Play
    9.     List4.ListIndex = Number - 1
    10.    
    11.     If Number > (List4.ListCount - 1) Then Number = 1 Else Number = Number + 1
    12. End Sub

  27. #27

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2006
    Posts
    448

    Re: List box question...

    Okay, your code is working: But, once you push the play button, the song starts, so you push it again, the same song starts over, then you push it again and it moves to the next song using the same cycle :-/
    "Remember, remember the 5th of November, the gun powder treason and plot. I know of no reason why the gun powder treason should ever be forgot."

  28. #28
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: List box question...

    VB Code:
    1. 'General declarations
    2. Dim Number As Integer
    3.  
    4. Private Sub Play_Click()
    5.    List4.ListIndex = Number
    6.  
    7.     MediaPlayer1.FileName = List4.List(Number)
    8.     MediaPlayer1.Play
    9.     List4.ListIndex = Number
    10.    
    11.     [U]Number = Number + 1[/U]
    12.     If Number > (List1.ListCount - 1) Then Number = 0
    13. End Sub

    Oops forgot to add the Number = Number + 1, this should work
    Last edited by DigiRev; Nov 14th, 2006 at 11:24 PM.

  29. #29

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2006
    Posts
    448

    Re: List box question...

    You can stop trying to write codes if you like.. cuz that just plays the first song. Ifyou push it again, it restarts the first song..
    "Remember, remember the 5th of November, the gun powder treason and plot. I know of no reason why the gun powder treason should ever be forgot."

  30. #30
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: List box question...

    I edited the above code. Try one more time and see if that works.

  31. #31
    Lively Member djklocek's Avatar
    Join Date
    Aug 2006
    Posts
    107

    Re: List box question...

    Please create label1 and label2 and see how it changes when clicking command1 button. For me it works.

    VB Code:
    1. Private Sub List4_Click()
    2.  
    3. Number = List4.ListIndex
    4. Label2.Caption = Number
    5.  
    6. End Sub
    7.  
    8. Private Sub Command1_Click()
    9.  
    10. Label1.Caption = List4.List(Number)
    11. Number = Number + 1
    12. Label2.Caption = Number
    13.  
    14. End Sub

    And of course you have to make a Dim Numer as Integer statement in general declarations for your form.
    Last edited by djklocek; Nov 14th, 2006 at 11:32 PM.

  32. #32

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2006
    Posts
    448

    Re: List box question...

    Did what you said:

    When i pushed play, nothing happened .. except one of your listbox said the file name that was playing, and the other listbox said 1. Then i clicked on the file in the listbox, and pushed play. Song played, but if button pushed again it just started over again..
    "Remember, remember the 5th of November, the gun powder treason and plot. I know of no reason why the gun powder treason should ever be forgot."

  33. #33

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2006
    Posts
    448

    Re: List box question...

    i mean label not listbox
    "Remember, remember the 5th of November, the gun powder treason and plot. I know of no reason why the gun powder treason should ever be forgot."

  34. #34
    Lively Member djklocek's Avatar
    Join Date
    Aug 2006
    Posts
    107

    Re: List box question...

    Quote Originally Posted by k0zz
    Did what you said:

    When i pushed play, nothing happened .. except one of your listbox said the file name that was playing, and the other listbox said 1.
    That's right. That should happen because Number has no value before clicking a listbox. You can put a Number = 0 when after listing songs.

    Quote Originally Posted by k0zz
    Then i clicked on the file in the listbox, and pushed play. Song played, but if button pushed again it just started over again.
    Label1.Caption = List4.List(Number) - you have this statement. what does it show? Is it still the same when clicking button? Or it's changing but mediaplayer plays the same all the time?

  35. #35

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2006
    Posts
    448

    Re: List box question...

    I dunno man... Thanks for all the help but uh... I don't really need this function newayz I have one more question for you if you don't mind..
    "Remember, remember the 5th of November, the gun powder treason and plot. I know of no reason why the gun powder treason should ever be forgot."

  36. #36
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: List box question...

    VB Code:
    1. 'General declarations
    2. Dim Number As Integer
    3.  
    4. Private Sub Play_Click()
    5.    List4.ListIndex = Number
    6.  
    7.     MediaPlayer1.FileName = List4.List(Number)
    8.     MediaPlayer1.Play
    9.     List4.ListIndex = Number
    10.    
    11.     [U]Number = Number + 1[/U]
    12.     If Number > (List1.ListCount - 1) Then Number = 0
    13. End Sub

    This doesn't work? :/

  37. #37

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2006
    Posts
    448

    Re: List box question...

    Nope :| .. Ima get alil rest.. i got another questoin i'd like to ask you tomorrow though.. if thats okay
    "Remember, remember the 5th of November, the gun powder treason and plot. I know of no reason why the gun powder treason should ever be forgot."

  38. #38
    Lively Member djklocek's Avatar
    Join Date
    Aug 2006
    Posts
    107

    Re: List box question...

    Quote Originally Posted by k0zz
    I don't really need this function newayz


    Yeah, get some sleep and ask again anytime.

    Thanx DigiRev

  39. #39
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: List box question...

    Oh well I tried. I don't know why I'm having such a hard time with the easy stuff. :/

    Anyway I'll have VB tomorrow so it should be no problem getting it worked out.


  40. #40

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2006
    Posts
    448

    Re: List box question...

    I don't know if you guys found the problem to my last question... but I have yet another...

    I'm using this code, given to me by djklocek...

    VB Code:
    1. For i = 2 To UBound(tmp)
    2. List1.AddItem tmp(i)
    3. Next i
    4. List1.AddItem tmp(1)
    The code works great.. but.. the only problem is that you can't add just ONE file. It works good for 2 or more files, but if i laod one file it says subscript out of range, and highlights List1.AddItem tmp(1) .. can we fix this? (other than changing the 1 to a 0)
    "Remember, remember the 5th of November, the gun powder treason and plot. I know of no reason why the gun powder treason should ever be forgot."

Page 1 of 2 12 LastLast

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