HELP: Downloading MS Access file in VB6 App using INET control |
Author: |
Message: |
Salem
Senior Member
Posts: 769 Reputation: 16
37 / /
Joined: May 2004
|
O.P. HELP: Downloading MS Access file in VB6 App using INET control
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
Was i Helpful?[/url]
|
|
06-02-2005 01:35 PM |
|
|
RaceProUK
Elite Member
Posts: 6073 Reputation: 57
39 / /
Joined: Oct 2003
|
RE: HELP: Downloading MS Access file in VB6 App using INET control
This may sound obvious, but are you performing a text or binary transfer?
|
|
06-02-2005 01:51 PM |
|
|
Salem
Senior Member
Posts: 769 Reputation: 16
37 / /
Joined: May 2004
|
O.P. RE: RE: HELP: Downloading MS Access file in VB6 App using INET control
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
Was i Helpful?[/url]
|
|
06-02-2005 01:54 PM |
|
|
Hah
Full Member
Im in a good mood - take advantage!
Posts: 224
37 / / –
Joined: May 2003
|
RE: HELP: Downloading MS Access file in VB6 App using INET control
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
This post was brought to you by Hah!
(and he takes no responsibility for it )
{Current Web Site}
|
|
06-03-2005 12:59 PM |
|
|
Salem
Senior Member
Posts: 769 Reputation: 16
37 / /
Joined: May 2004
|
O.P. RE: RE: HELP: Downloading MS Access file in VB6 App using INET control
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
Was i Helpful?[/url]
|
|
06-03-2005 01:13 PM |
|
|
Mike
Elite Member
Meet the Spam Family!
Posts: 2795 Reputation: 48
32 / /
Joined: Mar 2003
|
RE: HELP: Downloading MS Access file in VB6 App using INET control
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
|
|
06-03-2005 02:01 PM |
|
|
Salem
Senior Member
Posts: 769 Reputation: 16
37 / /
Joined: May 2004
|
O.P. RE: RE: HELP: Downloading MS Access file in VB6 App using INET control
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
This post was edited on 06-03-2005 at 02:36 PM by Salem.
Was i Helpful?[/url]
|
|
06-03-2005 02:26 PM |
|
|
Mike
Elite Member
Meet the Spam Family!
Posts: 2795 Reputation: 48
32 / /
Joined: Mar 2003
|
RE: HELP: Downloading MS Access file in VB6 App using INET control
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.
|
|
06-03-2005 02:49 PM |
|
|
Hah
Full Member
Im in a good mood - take advantage!
Posts: 224
37 / / –
Joined: May 2003
|
RE: HELP: Downloading MS Access file in VB6 App using INET control
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.
This post was brought to you by Hah!
(and he takes no responsibility for it )
{Current Web Site}
|
|
06-03-2005 02:58 PM |
|
|
Salem
Senior Member
Posts: 769 Reputation: 16
37 / /
Joined: May 2004
|
O.P. RE: RE: HELP: Downloading MS Access file in VB6 App using INET control
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?
Was i Helpful?[/url]
|
|
06-03-2005 03:00 PM |
|
|
Pages: (2):
« First
[ 1 ]
2
»
Last »
|
|