FileSystem Object with Arrays + passing arrays to Function Please!!!!!!!!!!!!!!!!!!!!1

I want copy the files one system to another system through VB FileSystem.
This my code below.I want pass the Arrays(arrayOfFileNames()) to function(displayFiles) ...
but none of the  file names are displayed...
How can i do it?

If any one knows Please help me....
Advance thanks.........

Private Sub Command1_Click()
Dim loopint As Integer
Dim Count As Integer

Set fso = New Scripting.FileSystemObject
Set mainFilesFolder = fso.GetFolder("C:\Archive\2\957\1024")
Set recipientFiles = mainFilesFolder.Files
Count = 0
For Each tmpFiles In recipientFiles
    Count = Count + 1
Next
' ReDim Preserve arrayOfFileNames(Count) As String
ReDim arrayOfFileNames(Count)
For Each tmpFiles In recipientFiles
    loopint = 1
    arrayOfFileNames(loopint) = tmpFiles.name
    'MsgBox arrayOfFileNames(loopint)
    loopint = loopint + 1

Next tmpFiles

loopint = 0
'Count = 0

displayFiles arrayOfFileNames
End Sub


Private Function displayFiles(arrayOfFileNames)
' MsgBox arrayOfFileNames()
'Dim tempArray
'tempArray = arrayOfFileNames
Dim i As Integer
Dim arrSize As Integer

 arrSize = UBound(arrayOfFileNames)
 For i = 0 To arrSize
    MsgBox arrayOfFileNames(i)
 Next i

 End Function


bye
Caroline
caroline_us_2003Asked:
Who is Participating?
 
afzal1299Connect With a Mentor Commented:
Well, firstly part of the problem is a simple mistake.  The "loopint = 1" is inside the for/next -- so it will always store it in that one place.

YOUR CODE:
   For Each tmpFiles In recipientFiles
      loopint = 1
      arrayOfFileNames(loopint) = tmpFiles.name
      'MsgBox arrayOfFileNames(loopint)
      loopint = loopint + 1
   
   Next tmpFiles


SHOULD READ:
   loopint = 1
   For Each tmpFiles In recipientFiles
      arrayOfFileNames(loopint) = tmpFiles.name
      'MsgBox arrayOfFileNames(loopint)
      loopint = loopint + 1
   Next tmpFiles

================

Also, I would review:
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20377240.html

It is a big complex but it does the job well.

0
 
TDC_LuCiFeRCommented:
your displayFiles function should look something like this:


Private Function displayFiles(arrayOfFileNames() As String)

this means a pointer to the Array was passed to the procedure, not a copy of the actual Array itself. You really should specify the procedure header in this way…

Private Function displayFiles(ByRef arrayOfFileNames() As String)


0
 
caroline_us_2003Author Commented:
Dear afzal1299 ,
                   thanks lot...
                   Thanks for your help...
                   Its working fine...


 I appreciate everyone's comments and helping me through this issue.

Thanks,
Caroline
0
All Courses

From novice to tech pro — start learning today.