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

Posted on 2003-03-21
Medium Priority
Last Modified: 2012-05-04
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
' 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

Question by:caroline_us_2003
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 8182664
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)


Accepted Solution

afzal1299 earned 120 total points
ID: 8182809
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.

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

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


Also, I would review:

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


Author Comment

ID: 8185301
Dear afzal1299 ,
                   thanks lot...
                   Thanks for your help...
                   Its working fine...

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


Featured Post

Technology Partners: 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’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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 Month11 days, 1 hour left to enroll

770 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