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.

at_the_biginningAsked:
Who is Participating?
 
game-masterCommented:

u cant add the ctr to vbNormal...

can u post ur code with regards to that procedure...



game-master
0
 
game-masterCommented:


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
0
 
at_the_biginningAuthor Commented:
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

0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
game-masterCommented:


Private Sub Command1_Click()

DIM ctr as integer

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

Next
End Sub


game-master
0
 
at_the_biginningAuthor Commented:

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


0
 
game-masterCommented:


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
0
 
at_the_biginningAuthor Commented:

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.


0
 
game-masterCommented:


'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
0
 
at_the_biginningAuthor Commented:

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?


0
 
game-masterCommented:


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
0
 
at_the_biginningAuthor Commented:

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.

0
 
at_the_biginningAuthor Commented:

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)"

0
 
at_the_biginningAuthor Commented:

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.
0
 
JackOfPHCommented:
Just helping my friend (Game-master)...

Try this....

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

Dim fso As New FileSystemObject

Dim fld As Folder

Private Sub cmdSetSelectedToNormalAttributes_Click()

    Dim n   As Integer
    Dim fle As File
   
    For n = 0 To List1.ListCount - 1
   
        If List1.Selected(n) Then
       
            Set fle = fso.GetFile(fso.BuildPath(fld, List1.List(s)))
       
            fle.Attributes = Normal
       
        End If
   
    Next

End Sub

Private Sub Form_Load()

    Set fld = fso.GetSpecialFolder(TemporaryFolder)

    Dim fle As File

    For Each fle In fld.Files
   
        List1.AddItem fle.Name
       
    Next

End Sub

That uses a listbox [List1], and a command button called cmdSetSelectedToNormalAttributes.

It references the Scripting Runtime Library for file handling.
0
 
at_the_biginningAuthor Commented:

Hey!!! Wonderfull :-)
Thank You Body
0
 
peetmCommented:
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.
0
 
at_the_biginningAuthor Commented:

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

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

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

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.

                        :-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.