|
-
Nov 14th, 2006, 07:25 PM
#1
Thread Starter
Hyperactive Member
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."
-
Nov 14th, 2006, 07:31 PM
#2
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
-
Nov 14th, 2006, 07:32 PM
#3
Lively Member
Re: List box question...
VB Code:
For i = 0 to Ubound(tmp)
List4.AddItem tmp(i)
Next i
-
Nov 14th, 2006, 07:40 PM
#4
Thread Starter
Hyperactive Member
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."
-
Nov 14th, 2006, 07:43 PM
#5
Re: List box question...
 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).
-
Nov 14th, 2006, 07:43 PM
#6
Lively Member
Re: List box question...
Hello.
There is a property of Common Dialog Control named MaxFileSize (default =260). Please change it. Regards
-
Nov 14th, 2006, 07:46 PM
#7
Thread Starter
Hyperactive Member
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."
-
Nov 14th, 2006, 07:48 PM
#8
Re: List box question...
 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:
-
Nov 14th, 2006, 07:52 PM
#9
Thread Starter
Hyperactive Member
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."
-
Nov 14th, 2006, 08:00 PM
#10
Lively Member
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?
-
Nov 14th, 2006, 08:01 PM
#11
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
-
Nov 14th, 2006, 08:02 PM
#12
Thread Starter
Hyperactive Member
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."
-
Nov 14th, 2006, 08:05 PM
#13
Thread Starter
Hyperactive Member
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."
-
Nov 14th, 2006, 08:12 PM
#14
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.
-
Nov 14th, 2006, 08:19 PM
#15
Lively Member
Re: List box question...
 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:
For i = 2 To UBound(tmp)
List1.AddItem tmp(i)
Next i
List1.AddItem tmp(1)
Assuming that tmp(0) is a path
Last edited by djklocek; Nov 14th, 2006 at 08:23 PM.
-
Nov 14th, 2006, 08:45 PM
#16
Thread Starter
Hyperactive Member
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."
-
Nov 14th, 2006, 08:48 PM
#17
Lively Member
Re: List box question...
No problem man, do not hesitate to rate if you're satisfied
Regards
-
Nov 14th, 2006, 09:06 PM
#18
Thread Starter
Hyperactive Member
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."
-
Nov 14th, 2006, 09:16 PM
#19
Thread Starter
Hyperactive Member
"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."
-
Nov 14th, 2006, 09:18 PM
#20
Lively Member
Re: List box question...
Please post your button_click code.
-
Nov 14th, 2006, 10:30 PM
#21
Thread Starter
Hyperactive Member
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."
-
Nov 14th, 2006, 10:53 PM
#22
Lively Member
Re: List box question...
VB Code:
'In general declarations
Dim Number as Integer
Private Sub List4_Click()
Number = List4.ListIndex
End Sub
Private Sub Play_Click()
On Error Resume Next
MediaPlayer1.FileName = List4.List(Number)
MediaPlayer1.Play
Number = Number + 1
End Sub
That's not a sophisticated method but maybe it will work for you
-
Nov 14th, 2006, 10:56 PM
#23
Thread Starter
Hyperactive Member
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."
-
Nov 14th, 2006, 10:59 PM
#24
Re: List box question...
Ah, good, VBCode is working again.
Try changing it to this:
VB Code:
'In general declarations
Dim Number as Integer
Private Sub List4_Click()
Number = List4.ListIndex
End Sub
Private Sub Play_Click()
On Error Resume Next
If Number > List4.ListCount Then Number = 1 Else Number = Number + 1
MediaPlayer1.FileName = List4.List(Number)
MediaPlayer1.Play
End Sub
-
Nov 14th, 2006, 11:02 PM
#25
Thread Starter
Hyperactive Member
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."
-
Nov 14th, 2006, 11:08 PM
#26
Re: List box question...
It's hard to test without VB on this computer...try this...
VB Code:
'General declarations
Dim Number As Integer
Private Sub Play_Click()
If Number = 0 Then Number = 1
MediaPlayer1.FileName = List4.List(Number-1)
MediaPlayer1.Play
List4.ListIndex = Number - 1
If Number > (List4.ListCount - 1) Then Number = 1 Else Number = Number + 1
End Sub
-
Nov 14th, 2006, 11:11 PM
#27
Thread Starter
Hyperactive Member
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."
-
Nov 14th, 2006, 11:19 PM
#28
Re: List box question...
VB Code:
'General declarations
Dim Number As Integer
Private Sub Play_Click()
List4.ListIndex = Number
MediaPlayer1.FileName = List4.List(Number)
MediaPlayer1.Play
List4.ListIndex = Number
[U]Number = Number + 1[/U]
If Number > (List1.ListCount - 1) Then Number = 0
End Sub
Oops forgot to add the Number = Number + 1, this should work
Last edited by DigiRev; Nov 14th, 2006 at 11:24 PM.
-
Nov 14th, 2006, 11:22 PM
#29
Thread Starter
Hyperactive Member
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."
-
Nov 14th, 2006, 11:25 PM
#30
Re: List box question...
I edited the above code. Try one more time and see if that works.
-
Nov 14th, 2006, 11:28 PM
#31
Lively Member
Re: List box question...
Please create label1 and label2 and see how it changes when clicking command1 button. For me it works.
VB Code:
Private Sub List4_Click()
Number = List4.ListIndex
Label2.Caption = Number
End Sub
Private Sub Command1_Click()
Label1.Caption = List4.List(Number)
Number = Number + 1
Label2.Caption = Number
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.
-
Nov 14th, 2006, 11:40 PM
#32
Thread Starter
Hyperactive Member
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."
-
Nov 14th, 2006, 11:44 PM
#33
Thread Starter
Hyperactive Member
"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."
-
Nov 14th, 2006, 11:45 PM
#34
Lively Member
Re: List box question...
 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.
 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?
-
Nov 14th, 2006, 11:47 PM
#35
Thread Starter
Hyperactive Member
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."
-
Nov 14th, 2006, 11:48 PM
#36
Re: List box question...
VB Code:
'General declarations
Dim Number As Integer
Private Sub Play_Click()
List4.ListIndex = Number
MediaPlayer1.FileName = List4.List(Number)
MediaPlayer1.Play
List4.ListIndex = Number
[U]Number = Number + 1[/U]
If Number > (List1.ListCount - 1) Then Number = 0
End Sub
This doesn't work? :/
-
Nov 14th, 2006, 11:50 PM
#37
Thread Starter
Hyperactive Member
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."
-
Nov 14th, 2006, 11:55 PM
#38
Lively Member
-
Nov 14th, 2006, 11:56 PM
#39
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.
-
Nov 15th, 2006, 07:45 PM
#40
Thread Starter
Hyperactive Member
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:
For i = 2 To UBound(tmp)
List1.AddItem tmp(i)
Next i
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."
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|