Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HELP- Listing Multiple selected files from a FileListBox in a ListBox

Status
Not open for further replies.

robbaggio

Programmer
Jun 11, 2002
31
US
I have a filelistbox File1 and a listbox List1. When i run prog I selected multiple files from File1 and then hit a command button which is supposed ot list the selected files in List1. This is the code i have right now:

Dim i As Integer
For i = 0 To File1.ListCount - 1
If File1.List(i).Selected = True Then
List1.AddItem File1.List(i)
End If
Next

I am getting a runtime error that says .List is an invalid qualifier in the If...... line. Any ideas on how to rearange this line or the loop to get this to work. I have a feeling the problem is with the
If File1.List(i).Selected = True, in that the .Selected part is wrong.

Any help would be greatly appreciated.
Thanks
robbaggio
 
Ok, i figured out part of the problem. Now i have this code:
For i = 0 To CheckedInFiles.ListCount - 1
If CheckedInFiles.Selected(i) = True Then
GetList.AddItem CheckedInFiles.List(i)
End If
Next

Which seems to work but says for the AddItem method i need a valid object. I think the problem is that AddItem requires a string and it is getting the actual file from the FileListBox not a string that represents the file. So I assume i need to caste to a string or convert or something, but how do i do that?

Thanks again
robbaggio
 
You should be doing this:

Dim i As Integer
For i = 0 To File1.ListCount - 1
If File1.Selected(i) = True Then
List1.AddItem File1.List(i)
End If
Next
 
I must have just posted right after you did... ha!

I copied and pasted your code, added the controls and it works fine on my computer.

Not sure what to tell ya!
 
Yeah, i dont know why but for some reason it isnt working.
I also tried make a temp string variable and trying to cast like this:
temp = CStr(File1.List(i))
and then doing
List1.AddItem temp

but get same error

Thanks for the help anyway bjd4jc!

Hopefully i can figure out what is wrong

robbaggio
 
Are you sure that you have a control called GetList? Or do you have another variable called GetList?

That would be my only other guess.

What is the exact error number and message?
 
Oops, that was the problem, stupid error on my part. The GetList ListBox was in another frame that popped up so i had to add that frames name to the AddItem line:

frmGet.GetList.AddItem CheckedInFiles.Index(i)

Thanks for your help bjd4jc!

robbaggio
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top