Results 1 to 10 of 10

Thread: What is wrong with my downloads class??

  1. #1

    Thread Starter
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    Angry What is wrong with my downloads class??

    I've created an app to download multiple files from internet. To be more fast, I've created also an ActiveX EXE only to download the files.

    I send the file origin and file destination to the Class (ActiveX EXE).

    This is my form code:
    Code:
    Private Sub Command1_Click()
    
    Dim i As Integer
    Dim Download() As DownloadClasse.Internet
    
    
    Me.ProgressBar1.Max = Me.MSHFlexGrid1.Rows - 1
    ReDim Download(Me.MSHFlexGrid1.Rows - 1)
        
        
    For i = 1 To Me.MSHFlexGrid1.Rows - 1
        Set Download(i) = New DownloadClasse.Internet
        Download(i).DownloadFich Me.MSHFlexGrid1.TextMatrix(i, 0), Me.MSHFlexGrid1.TextMatrix(i, 1)     'send the filename to
    
        Me.ProgressBar1.Value = i
        Set Download(i) = Nothing
        
    Next i
    
    Me.ProgressBar1.Value = 0
    
    End Sub
    This is the class

    Code:
    Option Explicit
    Public Function DownloadFich(ArqURL As String, Arqtemp As String)
    
    Dim arquivo() As Byte
    Dim Inet1 As Inet
    
    Open Arqtemp For Binary Access Write As #1
    
    arquivo() = Inet1.OpenURL(ArqURL, icByteArray)
    Put #1, , arquivo()
    
    Close #1
    
    End Function
    I get the 91 error!
    I know that it is a nasty simple error but, what am I doing wrong???
    Last edited by RS_Arm; Aug 28th, 2007 at 03:51 PM.

  2. #2
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: What is wrong with my downloads class??

    What line of code is it highlighting?

    Also, try changing this line:

    Code:
    ReDim Download(Me.MSHFlexGrid1.Rows - 1)
    to
    Code:
    ReDim Download(1 To Me.MSHFlexGrid1.Rows - 1)
    Since your code seems to be base 1 for arrays.

  3. #3

    Thread Starter
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    Re: What is wrong with my downloads class??

    Nop. Got the same error. By the way, it's in the line were I call the Class.

    Code:
    '...
     Download(i).DownloadFich Me.MSHFlexGrid1.TextMatrix(i, 0), Me.MSHFlexGrid1.TextMatrix(i, 1)
    '...
    Thank you

  4. #4
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: What is wrong with my downloads class??

    Quote Originally Posted by RS_Arm
    Nop. Got the same error. By the way, it's in the line were I call the Class.

    Code:
    '...
     Download(i).DownloadFich Me.MSHFlexGrid1.TextMatrix(i, 0), Me.MSHFlexGrid1.TextMatrix(i, 1)
    '...
    Thank you
    Well you're declaring it as a New Download.Internet so I don't think that's the problem.

    Maybe it is a problem with the FlexGrid? Try replacing that with a literal string just to see if it gets rid of the error, ie:

    Code:
    Download(i).DownloadFich "http://www.vbforums.com/favicon.ico", App.Path & "\favicon.ico"

  5. #5

    Thread Starter
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    Re: What is wrong with my downloads class??

    I've tried your suggestion and still got the same error.

    Thank you.

  6. #6
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: What is wrong with my downloads class??

    I think the error comes from the Class with Inet1 hasn't been set:
    Set Inet1 = ...

  7. #7

    Thread Starter
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    Re: What is wrong with my downloads class??

    Could you be more explicit? Where should i add "set Inet1=..."? At this line in class?
    Code:
    arquivo() = Inet1.OpenURL(ArqURL, icByteArray)

  8. #8
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: What is wrong with my downloads class??

    Inet1 is an object? You just Dim it, you haven't Create it, so you cannot use it.
    I am not sure where "Inet" comes from, but it may be like this:
    Code:
    Dim Inet1 as New Inet
    or
    Code:
    Dim Inet1 as Inet
    ...
    Set Inet1 = New Inet
    This must be done before you can use: Inet1.OpenURL ...
    After you finish using it you should: Set Inet1 = Nothing

    Your idea of creating DownloadClass is smart, but I am not sure how faster it can be. From my point of view, you don't need to create each Download(i) for each download action, you can use just a single Download to do it as below:
    Code:
    Private Sub Command1_Click()
       Dim i As Integer
       Dim Download As DownloadClasse.Internet
    
       Me.ProgressBar1.Max = Me.MSHFlexGrid1.Rows - 1
       Set Download = New DownloadClasse.Internet
       For i = 1 To Me.MSHFlexGrid1.Rows - 1
          Download.DownloadFich Me.MSHFlexGrid1.TextMatrix(i, 0), Me.MSHFlexGrid1.TextMatrix(i, 1)     'send the filename to
          Me.ProgressBar1.Value = i
       Next i
       Set Download = Nothing
       Me.ProgressBar1.Value = 0
    End Sub
    Last edited by anhn; Aug 28th, 2007 at 10:34 PM.

  9. #9

    Thread Starter
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    Re: What is wrong with my downloads class??

    I think i know why my app doesn't work. Inet is a ocx object, Even if I add it to my ActiveX app and instantiate it, it wont be recognized as a object (i think). So, if someone can confirm this, i would be very greatfull.
    Thank you.

  10. #10

    Thread Starter
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    Re: What is wrong with my downloads class??

    I think i got it!!

    In my class:
    Code:
    Option Explicit
    Public Function DownloadFich(ArqURL As String, Arqtemp As String, Inet1 As Inet)
    
    Dim arquivo() As Byte
    'Dim Inet1 As Inet
    
    
    Open Arqtemp For Binary Access Write As #1
    
    arquivo() = Inet1.OpenURL(ArqURL, icByteArray)
    Put #1, , arquivo()
    
    Close #1
    
    End Function
    in my form:
    Code:
    Private Sub Command1_Click()
       Dim i As Integer
       Dim Download As Class1
       
       Set Download = New Class1
       Download.DownloadFich "http://www.vbforums.com/images/statusicon/user_offline.gif", "C:\i.gif", Me.Inet1       'send the filename to"
       Set Download = Nothing
    
    End Sub
    (not tested yet)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width