Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

VB6 ListBox

Posted on 2009-04-19
22
Medium Priority
?
585 Views
Last Modified: 2012-05-06
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.

0
Comment
Question by:at_the_biginning
  • 13
  • 6
  • 2
  • +1
22 Comments
 
LVL 13

Expert Comment

by:game-master
ID: 24182210


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
 

Author Comment

by:at_the_biginning
ID: 24182341
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
 
LVL 13

Expert Comment

by:game-master
ID: 24182372


Private Sub Command1_Click()

DIM ctr as integer

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

Next
End Sub


game-master
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:at_the_biginning
ID: 24182411

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
 
LVL 13

Expert Comment

by:game-master
ID: 24182536


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
 

Author Comment

by:at_the_biginning
ID: 24182629

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
 
LVL 13

Expert Comment

by:game-master
ID: 24182654


'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
 

Author Comment

by:at_the_biginning
ID: 24182695

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
 
LVL 13

Expert Comment

by:game-master
ID: 24182714


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
 

Author Comment

by:at_the_biginning
ID: 24182770

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
 
LVL 13

Accepted Solution

by:
game-master earned 800 total points
ID: 24182816

u cant add the ctr to vbNormal...

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



game-master
0
 

Author Comment

by:at_the_biginning
ID: 24182873

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
 

Author Comment

by:at_the_biginning
ID: 24182914

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
 
LVL 15

Assisted Solution

by:JackOfPH
JackOfPH earned 800 total points
ID: 24182969
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
 
LVL 10

Assisted Solution

by:peetm
peetm earned 400 total points
ID: 24182988
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
 

Author Comment

by:at_the_biginning
ID: 24182995

Hey!!! Wonderfull :-)
Thank You Body
0
 
LVL 10

Expert Comment

by:peetm
ID: 24182998
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
 

Author Comment

by:at_the_biginning
ID: 24183004

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

Author Comment

by:at_the_biginning
ID: 24183015

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

Author Comment

by:at_the_biginning
ID: 24183036

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

Author Closing Comment

by:at_the_biginning
ID: 31572118
Thank You Guys :-)
0
 

Author Comment

by:at_the_biginning
ID: 24183084

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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month13 days, 13 hours left to enroll

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question