|
-
Nov 19th, 2002, 02:17 PM
#1
Thread Starter
Addicted Member
URLDownloadToFile question
Hey All,
I found this code on one of the threads...
Code:
Public 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
I was wondering if anyone could find any problem with changing
the last "IF" statement to something like the following...
Code:
If lngRetVal = 0 Then
DownloadFile = True
MsgBox "Download Complete!"
Else
DownloadFile = False
MsgBox "You are NOT Connected to the Internet!"
End If
Thanks in advance,
Ron
-
Nov 19th, 2002, 02:34 PM
#2
I see no problem with it. Have you tried it?
-
Dec 24th, 2002, 02:05 PM
#3
Hyperactive Member
Greetings and Salutatiions!
Just wanted to drop a note to say thanks for the code sample. It was just what I was looking for.
-
Dec 24th, 2002, 06:31 PM
#4
Frenzied Member
Returns one of the following values:
Private Const E_OUTOFMEMORY As Long = &H8007000E
The buffer length is invalid or there was insufficient memory to complete the operation.
Private Const S_OK As Long = &H0
The operation succeeded.
URLDownloadToFile will only return a non-zero value only if it doesn't have enough memory to do what it needs to.
Try using InternetGetConnectedState to see if the user is online or not.
VB Code:
Private Const INTERNET_CONNECTION_CONFIGURED = &H40
Private Const INTERNET_CONNECTION_LAN = &H2
Private Const INTERNET_CONNECTION_MODEM = &H1
Private Const INTERNET_CONNECTION_OFFLINE = &H20
Private Const INTERNET_CONNECTION_PROXY = &H4
Private Const INTERNET_RAS_INSTALLED = &H10
Private Declare Function InternetGetConnectedState Lib "wininet.dll" (ByRef lpdwFlags As Long, ByVal dwReserved As Long) As Long
Private Sub Form_Load()
'KPD-Team 2001
'URL: [url]http://www.allapi.net/[/url]
Dim Ret As Long
Me.AutoRedraw = True
'retrieve the connection status
InternetGetConnectedState Ret, 0&
'show the result
If (Ret And INTERNET_CONNECTION_CONFIGURED) = INTERNET_CONNECTION_CONFIGURED Then Me.Print "Local system has a valid connection to the Internet, but it may or may not be currently connected."
If (Ret And INTERNET_CONNECTION_LAN) = INTERNET_CONNECTION_LAN Then Me.Print "Local system uses a local area network to connect to the Internet."
If (Ret And INTERNET_CONNECTION_MODEM) = INTERNET_CONNECTION_MODEM Then Me.Print "Local system uses a modem to connect to the Internet."
If (Ret And INTERNET_CONNECTION_OFFLINE) = INTERNET_CONNECTION_OFFLINE Then Me.Print "Local system is in offline mode."
If (Ret And INTERNET_CONNECTION_PROXY) = INTERNET_CONNECTION_PROXY Then Me.Print "Local system uses a proxy server to connect to the Internet."
If (Ret And INTERNET_RAS_INSTALLED) = INTERNET_RAS_INSTALLED Then Me.Print "Local system has RAS installed."
End Sub
-
Jan 2nd, 2003, 10:33 AM
#5
Fanatic Member
Re: URLDownloadToFile question
Originally posted by rdcody
Hey All,
I found this code on one of the threads...
Code:
Public 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
I was wondering if anyone could find any problem with changing
the last "IF" statement to something like the following...
Code:
If lngRetVal = 0 Then
DownloadFile = True
MsgBox "Download Complete!"
Else
DownloadFile = False
MsgBox "You are NOT Connected to the Internet!"
End If
Thanks in advance,
Ron
The code is perfectly fine the way it is
VB Code:
If DownloadFile("http://www.vbforums.com/", "c:\a.txt") then
Msgbox "Download Complete"
else
Mesgbox "There was some kind of error"
End If
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|