HELP!!! Array Problems!!!!!!!!

I `m having a problem with VB as was wondering if you could help..

I`ve created a FTP- ish program to copy data from a specified location and paste it into another.
This works fine with a single selection but for multiple selections it only copies the last file..

i`m using an array to hold all the values that are selected but it doesn`t seem to bE recognising anything other than the last one.

this is the code i`m using:

filFilebox is the filebox with the selected files to transfer
dirDirBox is the name of the source directory box
dirDirBox2 is the name of the target directory box

Private Sub TransferFile_Click()

Dim item As Variant
Dim A As Variant

A = Array(filFileBox)
item = filFileBox.FileName

For Each item In Array(filFileBox)
        filname = dirDirBox.Path & "\" & filFileBox.FileName
        destpath = dirDirBox2.Path & "\" & filFileBox.FileName
        Progress.Text = "Source: " & filname & " Destination: " & destpath
        FileCopy filname, destpath
Next

Call filFileBox2.Refresh ' repaint the FileBox
End Sub

what`s going on?!?!?!?!?!?
Nina112599Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

simonbennettCommented:
Hi there,

See if this code works:

Private Sub TransferFile_Click()

Dim item As Variant
Dim A As Variant

A = Array(filFileBox)
'item = filFileBox.FileName  - i dont think you need this because it is set in the loop below.

For Each item In Array(filFileBox)
        filname = dirDirBox.Path & "\" & filFileBox.FileName
        destpath = dirDirBox2.Path & "\" & filFileBox.FileName
        Progress.Text = "Source: " & filname & " Destination: " & destpath
        FileCopy filname, destpath
        DoEvents ' clear out any unprocessed events before continuing.
Next

Call filFileBox2.Refresh ' repaint the FileBox
End Sub

Let me know if this is ok. Also - in debug, how many times does your loop execute? Is it just the once or for each item as you would expect?

HTH

Simon
0
corvanderlindenCommented:
There is only 1 item in your array
You can prove that by examining:

LBound(Array(List1))
UBound(Array(List1))
you should go through all selected item in your listbox
0
pmcgivernCommented:
Your array only has one item - the fileListBox.

Use this instead:

Private Sub TransferFile_Click()

Dim item As Variant

item = filFilebox.filename

For i = 0 To filFilebox.ListCount - 1
    If filFilebox.Selected(i) = True Then
        filname = dirDirBox.Path & "\" & filFilebox.List(i)
        destpath = dirDirBox2.Path & "\" & filFilebox.List(i)
        Progress.Text = "Source: " & filname & " Destination: " & destpath
        FileCopy filname, destpath
    End If
Next i

Call filFileBox2.Refresh ' repaint the FileBox
End Sub

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.