Smittey
Smittey

Reputation: 2490

Passing instance of Class Module

Say I create a new instance of a class module. Within that instance block I call another sub which calls the functions in the class module. How can I accomplish this? Currently I can't figure out how it is done. The following is an overview of my code:

...
With New FTPClient

    .ServerName = strServer
    .UserName = strUserName
    .Password = strPassword
    .remoteDir = strRemoteFolder
    .TransferType = "BINARY"
    .OpenFTP
    .OpenServer

    Upload()

    .CloseServer
    .CloseFTP

End With
...

Function Upload()

   ...
   .PutFile .remoteDir, currentFile, currentPath, "BINARY"
   ...

End Function

(.PutFile is a method in FTPClient.). Obviously it's having a bit of a fit and doesn't know what .PutFile or .remoteDir is. Is there some way of passing the instance of FTPClient to Upload?

Thanks,

Upvotes: 1

Views: 113

Answers (1)

Alex K.
Alex K.

Reputation: 175936

You need to pass it if its scoped in the calling code:

set client = new FTPClient
with client
   .ServerName = strServer
   ...
   Upload(client)


Function Upload(client as FTPClient)
   with client
      .PutFile .remoteDir, currentFile, currentPath, "BINARY"

Upvotes: 2

Related Questions