Results 1 to 4 of 4

Thread: link as a image?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2007
    Posts
    79

    Angry link as a image?

    how would i save a pictures url as a image file in vb like if i have
    HTML Code:
    http://www.google.com/intl/en_ALL/images/logo.gif
    and i want it so when something happends that url gets saved as a image how would i go about that

  2. #2
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: link as a image?

    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

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

    Re: link as a image?

    No need for the Inet control in your example.

  4. #4
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: link as a image?

    Oh yeah, I got that from a project that had Inet on it but for other reasons. Good point there, DR.

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