Working with Other Applications

image\rwnprg32.gif Integrating FTP Automation Commands into Visual Basic


The easiest way to integrate Reflection FTP Automation commands into a Visual Basic program is to first write a Visual Basic code module. Then, add the module to your Visual Basic project and make the modifications needed to integrate the Reflection FTP commands into your Visual Basic program. The following procedure provides a step-by-step description of the process:

Add an FTP OLE Automation Script to Your Visual Basic Project

1 Open an existing Visual Basic project file or start a new project file.

2 Click Add File on Visual Basic's File menu and select the FTP Automation code module you created. This adds the FTP Automation code module to your Visual Basic project.

3 Click References on Visual Basic's Tools menu and verify that Reflection FTP 1.0 TypeLib is selected. This adds the Reflection constant definitions to your Visual Basic project.

4 Select the name of your Reflection FTP code module from the Visual Basic Project window, then click View Code. Use these guidelines to update your code module as needed:

In the Procedure or Proc list box, give the procedure a descriptive name. For example, if your procedure logs into a specific site, you might name the procedure "LogonToMySite."

Add lines at the top of the procedure to dimension a variable as an Automation object, and then to create an instance of the object for the Reflection FTP Client. Other lines in the procedure that call Reflection FTP methods and properties should be prefixed with the name of the Reflection FTP object so that they reference the appropriate object.

Create a Visual Basic Control to Invoke the Reflection Procedure

One simple way to invoke the Reflection FTP procedure is to add a command button to a Visual Basic form, and have the button's Click procedure call the Reflection procedure:

1 Open the Visual Basic form on which you want to place the control that will invoke your Reflection FTP procedure. The startup form in a new Visual Basic project is called Form1.frm.

2 With your form open, double-click the command button in the Visual Basic Toolbox to add a command button to the form. Size and position the button, and change its Caption and Name properties as you like.

3 Double-click the command button to show the procedures associated with it.

4 Select the Click procedure from the Proc list (the Click procedure is usually the one shown by default when you double-click the control in step 3).

5 Within the Sub...End Sub statements that define the Click procedure, type the name of the Reflection FTP procedure you added to your Visual Basic project in the section above (the LogonToMySite procedure, for example).

6 Save your Visual Basic project and files, then run the program.

7 When you click the Visual Basic command button, it calls your Reflection FTP procedure, which creates a Reflection FTP Automation object to run Reflection FTP and perform the actions in the procedure.

Testing and Troubleshooting

Once you've integrated your Reflection FTP script into your Visual Basic program, you can run the program and step through the code in Visual Basic just as you would with any other Visual Basic program. Here are some tips for testing and troubleshooting Visual Basic programs that incorporate Reflection commands:

· If your Visual Basic program "hangs" while issuing a Reflection FTP command, you can use the Windows Task List to end the Reflection FTP task that's stuck.

· You should add some form of error handling to your Visual Basic programs to account for error conditions.

· You may want to add error handling to account for situations when a method that waits for a host response times out because the host response is not received.

· For each method, it is advisable to check the return value prior to continuing on to the next code action.

Related Topic

image\jump.gif Accessing Reflection FTP Methods and Properties from Visual Basic