how would i save a pictures url as a image file in vb like if i haveand i want it so when something happends that url gets saved as a image how would i go about thatHTML Code:http://www.google.com/intl/en_ALL/images/logo.gif
Printable View
how would i save a pictures url as a image file in vb like if i haveand i want it so when something happends that url gets saved as a image how would i go about thatHTML Code:http://www.google.com/intl/en_ALL/images/logo.gif
On a Form put a Command button, a Picturebox Control, and an Inet Control
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
Private Sub DownloadFile(URL As String, SaveAsFile As String)
Dim b As Long
b = URLDownloadToFile(0, URL, SaveAsFile, 0, 0)
End Sub
Private Function bFileExists(sFile As String) As Boolean
On Error Resume Next
bFileExists = ((GetAttr(sFile) And vbDirectory) = 0)
End Function
Private Function RemoveURLPath(ByVal FullPath As String) As String
Dim Pos As Long
Pos = InStrRev(FullPath, "/")
If Pos > 0 Then
RemoveURLPath = Mid$(FullPath, Pos + 1)
End If
End Function
Private Sub Command1_Click()
Dim sURL As String, SaveAs As String
sURL = "http://www.google.com/intl/en_ALL/images/logo.gif"
SaveAs = RemoveURLPath(sURL)
On Error Resume Next
If bFileExists(SaveAs) = False Then DownloadFile sURL, SaveAs
If bFileExists(SaveAs) = True Then Picture1.Picture = LoadPicture(SaveAs)
End Sub
No need for the Inet control in your example. :p ;)
Oh yeah, I got that from a project that had Inet on it but for other reasons. Good point there, DR.