Downloading with the ActiveX Control in Visual Basic


To use XFile's ActiveX download control from Visual Basic,

  • Add XFile to your list of VB references
  • Add SAAXFile to the components in your VB Toolbox
  • Add the AXFFileDownload control to your VB form

Exercise 11: Downloading with the ActiveX Control in Visual Basic

We will create a simple, one-file download in Visual Basic, using XFile's ActiveX control and its progress indicator. The project includes two forms: Form1 and Form2. Form1 contains the download control AXFFileDownload, and Form2 contains the progress indicator AXFFileProgress.

AXFFileDownload in Visual Basic
  1. Create a new, standard, Visual Basic project.

  2. Open the Project menu, select References.

  3. If you are using XFileSE, and check "SAXFile 2.0 Type Library". If you are using XFileEE, and check "SAXFileEE 2.0 Type Library". (See, XFile Editions for information on the two editions.)

  4. Open the Project menu, select Components.

  5. If you are using XFileSE, and check "SAAXFile 2.0 Type Library". If you are using XFileEE, and check "SAAXFileEE 2.0 Type Library". (See, XFile Editions for information on the two editions.)

  6. From the VB Toolbox, select the control AXFFileDownload and add it to Form1.

  7. Create a command button on Form1, name it Command1, and give it the caption "Download."

  8. Create a second command button on Form1, name it Command2, and give it the caption "Close."

  9. Enter the following code in the code section of Form1.

    Private Sub Command1_Click()
            Dim XFile As Object
            Set XFile = AXFFileDownload1.XFRequest
            Form2.Show
            End Sub
    
            Private Sub Command2_Click()
            Unload Me
            End Sub
    
            Private Sub Form_Load()
            AXFFileDownload1.AddFile "c:\temp\Pleasereadme.txt", "http://localhost/saxfilesamples/Readme.txt"
            End Sub
    
            Private Sub Form_Unload(Cancel As Integer)
            Unload Form2
            End Sub
          
  10. Add a second form (Form2) to the project.

  11. From the VB Toolbox, select the control AXFFileProgress and add it to Form 2.

  12. Enter the following code in the code section of Form2.

    Private Sub Form_Load()
            Me.Show
            ShowProgress
            StartTransfer
            End Sub
    
            Private Sub ShowProgress()
            AXFFileProgress1.XFRequest = Form1.AXFFileDownload1.XFRequest
            AXFFileProgress1.ShowProgress
            End Sub
    
            Private Sub StartTransfer()
            Form1.AXFFileDownload1.Start
            End Sub
          
Understanding the Script

Copyright © 2010 SoftArtisans, Inc. All rights reserved.