Link to home
Start Free TrialLog in
Avatar of at_the_biginning
at_the_biginningFlag for United States of America

asked on

VB6 ListBox

Hello Experts,

I would like to know how to work with this listsbox code

List1.ListIndex = List1.ListIndex + 1
If List1.ListIndex = List1.ListCount - 1 Then
For i = 0 To List1.ListCount - 1

well i am not sure if this is the code i need for my project.
to work with multiple files like in serie one after another, etc.

For example:

I have a ListBox in which i added the Drag and Drop option,
For this task i made a Folder in my desktop and then create
some files just for testing, .txt, .wav, .bmp, inside the Folder, etc.

Then i Draged and Droped those files to my ListBox in the project,
Now the idea about all this whole thing is that i want to learn how
to use this code so when i drag and drop the files into the ListBox
I can beging with a click of a buttom, rename, delete, change, etc.
but the problem i am having right now is that when ever i try to do
this action in the project i can only do it one at a time. :-(

My problem is that if i Drag and Drop like 23 files into the List
i am able to work only with one file at a time and for this i have
to keep pressing the action buttom for this to work. :-(

As i am a novice i don't know if i have explain this the right way.
anyway, any help will be very appreciate.

Thanks in advance.

Avatar of game-master
game-master
Flag of Philippines image



good afternoon..
try sumthing like this...

for ctr = 0 to list1.listcount -1

 'do ur code here...


next

'this codes denotes that your looping to the entire lists of the listbox

i hope i could give u some idea....


game-master
Avatar of at_the_biginning

ASKER

Hi

Thank you for replying.

I am getting a Variable not defined error:

For ctr = 0 To List1.ListCount - 1

it point to this part of the code: ctr

Can you please clear a bit the answer?

Private Sub Command1_Click()
For ctr = 0 To List1.ListCount - 1
'My code here...

Next
End Sub

Thanks



Private Sub Command1_Click()

DIM ctr as integer

For ctr = 0 To List1.ListCount - 1
'My code here...

Next
End Sub


game-master

Now i am not getting the error anymore, But it doesn't do what it suppose to do.

it does the same thing like i had it before.

I even change the properties of the ListBox to MultiSelet so i can select all the files path in the ListBox
but it did not work either.

Let me explain a bit more about what i need.

If i drog and drop few files to the ListBox to delete them, when i click the command buttom, the code
suppose to move to the next line in each selected Item in the ListBox, do you got me now?

Thanks game-master




can u post ur code here?

this example check the items on the list one by one...


    For ctr = 0 To List1.ListCount - 1
       
        MsgBox List1.List(ctr)
       
    Next






game-master

My code is not that big, is just this:

well atleast this is what i have so far.

Private Sub Command1_Click()
Dim ctr As Integer
For ctr = 0 To List1.ListCount - 1
       
MsgBox List1.List(ctr)
       
Next
End Sub

this code counts the lines of the ListBox, but it does not move down one after another
after reading the content of each line.

Let me give you an example:

in the same folder where i have my project i have created three files in this order:

File one.txt
File two.txt
File three.txt

Then to test the project i will acomplish the following code:

Private Sub Command1_Click()
Dim ctr As Integer
For ctr = 0 To List1.ListCount - 1
       
'The code this time will be... Killing the files.

Kill List1.List
       
Next
End Sub

Then if i got it right the code will kill one file after another till it have kill the three files in total.




'add ctr on the "kill list1.list"....
it should be like this...


Private Sub Command1_Click()
Dim ctr As Integer
For ctr = 0 To List1.ListCount - 1
       
'The code this time will be... Killing the files.

Kill List1.List(ctr)
       
Next
End Sub

Hey! this time worked, But there is only one thing, it only work with the Kill command.

i tried this other way:

SetAttr List1, vbNormal(ctr)

and it did not work :-(

I get a compile error: Expected array

what can this be?




unfortunately, u can't do it that way...
vbNormal is not a control array, therefore u cant just add ctr on it "vbNormal(ctr)"


game-master

If i do it this way:

SetAttr List1, "vbNormal(ctr)"

i get the following error:

Run-time error '13':

Type mismatch

Please! Please! oh man, there must be a way arround this code to make it work.

ASKER CERTIFIED SOLUTION
Avatar of game-master
game-master
Flag of Philippines image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

OK, lets use this example:

Private Sub Command1_Click()
Dim ctr As Integer
For ctr = 0 To List1.ListCount - 1
'My code here...
SetAttr List1, vbNormal
Next
End Sub

Add a ListBox and a Command buttom to a Form, then add the code above
thats just the normal code without any modification like you told me before.
i emant without the ==> "vbNormal(ctr)"


See game-master, what i am trying to make is something that can allow me to:
Rename, Delete, Setattr, And much more with out any limitation in ListBoxes.

well what i really want is to avoid the have to be doing one file at a time in each
line of the file path in the project ListBox, thats all, otherwise i have to keep the
buttom click after click in order to do my task in like 48 files in the project Listbox.

if there is another way to make this work in ListBoxes i would ike to know it.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

Hey!!! Wonderfull :-)
Thank You Body
Oh yes, and it works on files in your Temp folder as it is:

    Set fld = fso.GetSpecialFolder(TemporaryFolder)

Obviously, that would be a variable in your case - possibly set with a FolderList thingmy.

Also, the ListBox has Extended multi-select - so you can click/drag.

Hey Jack that worked so nice, just what i wanted :-)

Hey sorry to ask this question, but where is the option where i can click and split points?
Thanks

Nevermind, i got it. :-)
i been away from EE that everything here looks diferent for me.
Thank You Guys :-)

Thank you for helping me game-master,
and thank you Jack for fixing the code,
i also want to thanks peetm for the code he post,
i will check it and save it for future references in my project.

once again, Thank you guys.

                        :-)