Shoutbox

HELP: Downloading MS Access file in VB6 App using INET control - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: HELP: Downloading MS Access file in VB6 App using INET control (/showthread.php?tid=45680)

HELP: Downloading MS Access file in VB6 App using INET control by Salem on 06-02-2005 at 01:35 PM

I guys,

I hope someone can help me with my recent problem.

I'm trying to download a Microsoft Access from the net in my Visual Basic 6 application. I'm using the INET control.

I've previously used this method to download a basic text document and it worked fine. So i wanted to download a MS Access document and thought i'd just modify the URL that it downloads from. But this didn't work. The Access document created is not a recognised Access document. Access won't open it neither will the Visual Basic 8 ADODC connect to the downloaded access document. both say it is not a recognised Access document.

Below is the Visual Baisc 6 code used when loading the form that is to download the file.

code:
ProgressBar1.Max = 281
    Inet1.RequestTimeout = Timeout 'set timeout
    Destination = <path to which access document will be save> 'set destination file
    Inet1.Execute "<URL from which the access database will be downloaded>", "GET" 'Start the download of the specified file

This is the code that is executed when the status of the Inet control is changed:
code:
Static inProc As Boolean
    If Not inProc Then 'only execute this procedure, if it is the first call (DoEvents in this sub may call this event frequently
        inProc = True
        Debug.Print Timer, State
        Select Case State
            Case icResponseReceived 'Received something
                Dim vtData() As Byte 'Current Chunk
               
                Do While Inet1.StillExecuting
                    DoEvents
                Loop
                Do
                    DoEvents
                    vtData = Inet1.GetChunk(256, 1)
                    If UBound(vtData) = -1 Then Exit Do 'exit loop, if no Chunk could received
                    ReDim Preserve file(SafeUBoundFile + UBound(vtData) + 1) 'enlarge file-array
                    CopyMemory file(UBound(file) - UBound(vtData)), vtData(0), UBound(vtData) + 1 'copy received Chunk to the file-array
                    If UBound(vtData) <> 255 Then Exit Do 'if the length of the chunk is not 255, then it must be the last chunk of the file
                   
                    Dim tmp As Long
                    tmp = UBound(file) / 1024
                    If tmp > ProgressBar1.Max Then tmp = ProgressBar1.Max 'if KBs is higher then ProgressBar1.Max then truncated
                        ProgressBar1.Value = tmp 'update ProgressBar1
                Loop
               
                Inet1.Cancel
           
                Open Destination For Binary As #1 'Write file-array to destination-file
                Put #1, , file
                'Close #1
                Erase file 'free file-array
                'inProc = False
               
                FrmUpdate.Show
                Unload Me
               
        End Select
        inProc = False

    End If

Sorry if there is quite an obvious solution, but i haven't been programming for long and have tried many thing last night without success.

Thanks in advance
RileyM
RE: HELP: Downloading MS Access file in VB6 App using INET control by RaceProUK on 06-02-2005 at 01:51 PM

This may sound obvious, but are you performing a text or binary transfer?


RE: RE: HELP: Downloading MS Access file in VB6 App using INET control by Salem on 06-02-2005 at 01:54 PM

quote:
Originally posted by raceprouk
This may sound obvious, but are you performing a text or binary transfer?


I thought about that, but not sure where to change it to being a text or binary transfer. I tried looking but couldnt find anything
RE: HELP: Downloading MS Access file in VB6 App using INET control by Hah on 06-03-2005 at 12:59 PM

You should delete the "Destination" file before you write to it using binary as if the data already in the file in longer than that been downloaded, then the downloaded data will only go over the top of the existing data, causing corruption of the file.

I.e.

code:
Kill Destination

If this is the existing data:

hello my name is thomas

and the downloaded data is :

hello my name is tom

After writing it to the file you will end up with

hello my name is tommas

I.e. Corruption. Im just gonna look at your code now to see if  the downloading bit is alright,let me know if youve already sorted the problem.

Tah, Hah
RE: RE: HELP: Downloading MS Access file in VB6 App using INET control by Salem on 06-03-2005 at 01:13 PM

quote:
Originally posted by Hah
You should delete the "Destination" file before you write to it using binary as if the data already in the file in longer than that been downloaded, then the downloaded data will only go over the top of the existing data, causing corruption of the file.

I.e.

code:
Kill Destination

If this is the existing data:

hello my name is thomas

and the downloaded data is :

hello my name is tom

After writing it to the file you will end up with

hello my name is tommas

I.e. Corruption. Im just gonna look at your code now to see if  the downloading bit is alright,let me know if youve already sorted the problem.

Tah, Hah


Thanks

I have deleted the existsing "Destination" file before downloading the file. However i removed it manually, dunno if this wouldve had an effect.

I haven't been able to solve the problem yet

RileyM
RE: HELP: Downloading MS Access file in VB6 App using INET control by Mike on 06-03-2005 at 02:01 PM

Try using an API call to download the DB.

Example from AllApi:

code:
Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
Public Function DownloadFile(URL As String, LocalFilename As String) As Boolean
    Dim lngRetVal As Long
    lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
    If lngRetVal = 0 Then DownloadFile = True
End Function
Private Sub Form_Load()
    'example by Matthew Gates (Puff0rz@hotmail.com)
    DownloadFile "http://www.allapi.net", "c:\allapi.htm"
End Sub

RE: RE: HELP: Downloading MS Access file in VB6 App using INET control by Salem on 06-03-2005 at 02:26 PM

quote:
Originally posted by Mike2
Try using an API call to download the DB.

Example from AllApi:

code:
Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
Public Function DownloadFile(URL As String, LocalFilename As String) As Boolean
    Dim lngRetVal As Long
    lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
    If lngRetVal = 0 Then DownloadFile = True
End Function
Private Sub Form_Load()
    'example by Matthew Gates (Puff0rz@hotmail.com)
    DownloadFile "http://www.allapi.net", "c:\allapi.htm"
End Sub


Thanks Mike2, i am in the process of testing to see if it works.

How would i go about haing the progressbar update in order to show the progress of downloading the Access document? I had it working using my previous download method (see my code on in the first post), but how would i change the code to work with this new download method?

Edit: Also, where would i insert code for my program to perform a task once the download is complete.

Thanks in advance

RileyM
RE: HELP: Downloading MS Access file in VB6 App using INET control by Mike on 06-03-2005 at 02:49 PM

If you want to display a progress bar, then try looking at this: http://www.vbforums.com/showthread.php?t=319226

It is an auto-update program with source included, and, it displays a pbar of the download progress.

Also, put the rest of the code under the download line.

The code will continue executing after the download is finished.


RE: HELP: Downloading MS Access file in VB6 App using INET control by Hah on 06-03-2005 at 02:58 PM

Ive made some code which will download the file correctly however I was testing it using a big file (296meg) and forget to put a thing in to cancel the download so im gonna have to wait for that to finish before I can get the source.

Its based on betting the "Content-Length" header from the server on icResponceRecieved and then doing the rest on icResponceCompleted.


RE: RE: HELP: Downloading MS Access file in VB6 App using INET control by Salem on 06-03-2005 at 03:00 PM

quote:
Originally posted by Mike2
If you want to display a progress bar, then try looking at this: http://www.vbforums.com/showthread.php?t=319226

It is an auto-update program with source included, and, it displays a pbar of the download progress.

Also, put the rest of the code under the download line.

The code will continue executing after the download is finished.


So any code i put after the code u gave me will be executed once the download is complete?
RE: HELP: Downloading MS Access file in VB6 App using INET control by Hah on 06-03-2005 at 03:14 PM

Here's mine,

It's ok but it definately has problems:

1.) Will not download the file with the server doesn't send content-length header back on first responce, however it may work sometimes with a server and sometimes not, so its not reliable.

2.) Cancelling a download is a joke, then again it always seems to be when using Inet.

3.) Place any code to be executed after the download in a new sub and execute it after Me.Caption = "Download Complete"

My advice, if u dont want to be able to see speed and etc and dont want to be able to customise the transfer, deinately go with the ones above.

Edit: Help's if i attach it


RE: RE: HELP: Downloading MS Access file in VB6 App using INET control by Salem on 06-03-2005 at 03:17 PM

quote:
Originally posted by Mike2
If you want to display a progress bar, then try looking at this: http://www.vbforums.com/showthread.php?t=319226

It is an auto-update program with source included, and, it displays a pbar of the download progress.

Also, put the rest of the code under the download line.

The code will continue executing after the download is finished.


Thank-you Mike2. It is working. I think i'll leave the progressbar out for now
RE: HELP: Downloading MS Access file in VB6 App using INET control by Hah on 06-03-2005 at 03:27 PM

quote:
Originally posted by RileyM
Thank-you Mike2. It is working. I think i'll leave the progressbar out for now

This will do your progress bar for the above method
set the progress bar max to 100 (where mobjDownload is the actually name of the object you use for download and prgDownload is the object name of the progress bar)
code:
Private Sub mobjDownload_DownloadProgress(ByVal ReceivedBytes As Long, ByVal TotalBytes As Long)
    prgDownload.Value = CLng(100 * (ReceivedBytes / TotalBytes))
    DoEvents
End Sub


RE: RE: HELP: Downloading MS Access file in VB6 App using INET control by Salem on 06-03-2005 at 03:32 PM

quote:
Originally posted by Hah
quote:
Originally posted by RileyM
Thank-you Mike2. It is working. I think i'll leave the progressbar out for now

This will do your progress bar for the above method
set the progress bar max to 100 (where mobjDownload is the actually name of the object you use for download and prgDownload is the object name of the progress bar)
code:
Private Sub mobjDownload_DownloadProgress(ByVal ReceivedBytes As Long, ByVal TotalBytes As Long)
    prgDownload.Value = CLng(100 * (ReceivedBytes / TotalBytes))
    DoEvents
End Sub



I understand what you mean about prgDownload but not about mobjDownload. So you mean mobjDownload will become DownloadFile as in Mike2's code example above?
RE: HELP: Downloading MS Access file in VB6 App using INET control by Hah on 06-03-2005 at 07:12 PM

quote:
Originally posted by RileyM
I understand what you mean about prgDownload but not about mobjDownload. So you mean mobjDownload will become DownloadFile as in Mike2's code example above?


nah, which code have you got set up to download the file for you at the moment? Is it the liveupdate or Mike2's DownloadFile one?
RE: RE: HELP: Downloading MS Access file in VB6 App using INET control by Salem on 06-05-2005 at 11:06 AM

quote:
Originally posted by Hah
quote:
Originally posted by RileyM
I understand what you mean about prgDownload but not about mobjDownload. So you mean mobjDownload will become DownloadFile as in Mike2's code example above?


nah, which code have you got set up to download the file for you at the moment? Is it the liveupdate or Mike2's DownloadFile one?


oh sorry, i just saw your LiveUpdate submission after i had written my previos message.

I have Mike2's code setup to download the file.

Also is there any code you can give to display download speed and amount downloaded thus far using Mike2's code example?

Thanks