Nina112599
asked on
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?!?!?!?!?!?
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?!?!?!?!?!?
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
You can prove that by examining:
LBound(Array(List1))
UBound(Array(List1))
you should go through all selected item in your listbox
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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