Page 1 of 2 12 LastLast
Results 1 to 40 of 41

Thread: Saving web page temporarily

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2009
    Posts
    76

    Saving web page temporarily

    There is actualy an image on this particular page which i want to save on my disk.If not the disk then atleast load it on my picturebox1.
    The image has no url since it's not saved on the server.
    I simply want that whenever my browser navigates to this page,then this image should be copied to my hard disk or to my picturebox1 and it should always overwrite the previously saved image.
    Meaning,suppose i navigate to this page once,the image1 get's saved.Now if i again navigate to this page,the new image that comes up now should get saved by overwriting the image1 that was saved previously.
    Last edited by DragonBoy; Sep 13th, 2009 at 10:06 AM.

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Jul 2009
    Posts
    76

    Re: Saving web page temporarily

    I'm getting help from:
    http://www.vbforums.com/showthread.php?p=2268392

    but can anyone tell me where is it saving these temporary files ?

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Saving web page temporarily

    if you are using urldownloadtofile , which seems to be the method used in the thread you link to
    as you specify the filepath for urldownloadtofile it is where ever you want
    if you want to use the users temp folder use environ("temp") to get the full path

    if you are using someother method to save the files you need to specify what method you are using

    if you just want to save the source code of the webpage you can just write out the document element outerhtml to a text file

    try like
    vb Code:
    1. open environ("temp") & "\tempfile.htm") for output as 1
    2.     print #1, wb.document.documentelement.outerhtml
    3. close 1
    either of these will overwrite existing without prompt
    Last edited by westconn1; Sep 8th, 2009 at 04:55 PM.
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jul 2009
    Posts
    76

    Re: Saving web page temporarily

    I tried a method or two myself...but the problem is that they save the web page as a single file !!!

    What i want is that images be saved separately so that i can use those images when i want to...
    Is there anyway to same .bmp image from a web page ?


    The url of the image changes every time & i cannot download it twice so i have to find a way to copy it straight forwardly from my web control...

    I found this coding but it doesn't save any images for sites other then the three mentioned in it:
    Code:
    Option Explicit
     
    Dim x As Integer
    Dim b() As Byte
    Dim sUrl As String
    Dim sPicUrl As String
    Dim sPicName As String
    Dim iStart As Integer
    Dim ctl As Control
     
    Private Sub Form_Load()
    ColorForm
    List1.AddItem "www.Yahoo.com"
    List1.AddItem "www.google.com"
    List1.AddItem "www.visualbasicforum.com"
    End Sub
     
    Private Sub List1_Click()
     'Set clicked url to a string
     sUrl = List1.Text
     'Navigate to that url string
     WebBrowser1.Navigate sUrl
    End Sub
     
    Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
     
    List2.AddItem "=========="
    List2.AddItem sUrl
    
    On Error Resume Next
    MkDir App.Path & "\" & sUrl
     
    'Loop through all images in html
    For x = 0 To WebBrowser1.Document.Images.length - 1
       'Set image url to a string
       sPicUrl = WebBrowser1.Document.Images.Item(x).src
        
        'Sometimes the webbrowser control returns a default
        'error page on statup. If this is the case, do not
        'download images in this page
        If Mid$(sPicUrl, 1, 3) = "res" Then GoTo FirstLoad
            
        'Get the picture name out of the url string
        sPicName = Mid$(sPicUrl, InStrRev(sPicUrl, "/") + 1, Len(sPicUrl))
       
       'Download the picture
       DLpic
        'Add picture url to listbox
        List2.AddItem sPicUrl
        
    Next x
        List2.AddItem "----------"
    
    FirstLoad:
    End Sub
    Private Sub DLpic()
     
     'Open image url
     b() = Inet1.OpenURL(sPicUrl, icByteArray)
     
     'Open for a new file
     Open App.Path & "\" & sUrl & "\" & sPicName For Binary As #1
     
     Put #1, , b()
     Close #1
     Do
     DoEvents
      'Loop while still downloading
      Loop While Inet1.StillExecuting
     DoEvents
    End Sub
    
    Private Sub ColorForm()
    
    'Loop through all controls in form and
    'set the forcolor and backcolor for all listboxs
    For Each ctl In Me
     If TypeOf ctl Is ListBox Then
      With ctl
      .BackColor = RGB(95, 95, 143)
      .ForeColor = vbWhite
      End With
    End If
    Next
    
    
    'Loop through all controls in form and
    'set the forcolor and backcolor for all labels
    For Each ctl In Me
     If TypeOf ctl Is Label Then
      With ctl
      .BackColor = RGB(48, 111, 160)
      .ForeColor = vbWhite
      End With
     End If
    Next
    
    'Set the forms backcolor
    Me.BackColor = RGB(48, 111, 160)
    
    End Sub
    Last edited by DragonBoy; Sep 9th, 2009 at 12:57 AM.

  5. #5
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Saving web page temporarily

    you would need to loop through all the images in the document, then save them separately

    vb Code:
    1. for each ele in wb.document.getelementsbytagname("img")
    2.     urldownloadtofile ele.href, "c:\somepath\" & ele.nameProp
    3. next
    this is may have errors as i have not tested

    i also don't know how many images you can download at the same time, but if you do not clear the cache or pass the constant for the latest version it should get the image from the ie cache, which would be the same as displayed in the webbrowser control
    Last edited by westconn1; Sep 9th, 2009 at 04:53 AM.
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jul 2009
    Posts
    76

    Re: Saving web page temporarily

    westconn1:So,i should just put this code in a loop ?

    I need to download only 1 image from that web page but that page originally contains 4 to 6 images i think.
    If i put this coding in a loop,will it same all the images to my selected drive ?
    Even if it does copies all the images,it's fine with me.Aslong as that 1 image i need is downloaded aswell...

  7. #7
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Saving web page temporarily

    westconn1:So,i should just put this code in a loop ?
    that code is a loop

    if you know the link to the image you do not need loop, just download the image you want
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Jul 2009
    Posts
    76

    Re: Saving web page temporarily

    I think i'm very close now to solve this problem..but it's showing an error:
    Code:
    Compile error:
    
    Sub or function not define
    on the line:

    urldownloadtofile ele.href, "D:\Bots\ page " & ele.nameProp

    Can you give me the coding declaring this function aswell ?
    That would be great then


    I've tried this :
    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
    But it gives me an error on the same line saying:
    Code:
    Compile error:
    
    Argument not optional
    Last edited by DragonBoy; Sep 9th, 2009 at 07:54 AM.

  9. #9
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Saving web page temporarily

    you need to supply the last 2 arguments for the function, see the thread you linked to in the second post, for examples

    URLDownloadToFile 0, sURL, sLocalFile, 0, 0
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Jul 2009
    Posts
    76

    Re: Saving web page temporarily

    Quote Originally Posted by westconn1 View Post
    you need to supply the last 2 arguments for the function, see the thread you linked to in the second post, for examples

    URLDownloadToFile 0, sURL, sLocalFile, 0, 0
    Where should i exactly place this ?



    The problem with this image is that it's url is not fixed and it can't be requested for twice from the server cause it's generated automatically every time,so the server doesn't hold a copy of this image...

  11. #11
    Addicted Member Xiphias3's Avatar
    Join Date
    Jan 2009
    Location
    Clarendon, Jamaica
    Posts
    188

    Re: Saving web page temporarily

    From API-Guide. Very simple function.

    vb Code:
    1. 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
    2. Public Function DownloadFile(URL As String, LocalFilename As String) As Boolean
    3.     Dim lngRetVal As Long
    4.     lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
    5.     If lngRetVal = 0 Then DownloadFile = True
    6. End Function
    7. Private Sub Form_Load()
    8.     'example by Matthew Gates ([email protected])
    9.     DownloadFile "http://www.allapi.net", "c:\allapi.htm"
    10. End Sub

  12. #12
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Saving web page temporarily

    i would assume that the image loaded in the webbrowser can be copied then saved to file, but i do not know how to do that, though the execwb method may be able to be used to copy an image on the webpage to clipboard, all examples i have seen try to copy the entire page

    i believe that urldownloadtofile will get the image form cache if it exists there, but testing is a bit difficult, generally people always want to get the latest version and bypass the cache
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  13. #13
    Addicted Member Xiphias3's Avatar
    Join Date
    Jan 2009
    Location
    Clarendon, Jamaica
    Posts
    188

    Re: Saving web page temporarily

    EDIT:
    Westconn1, I agree with your approach about Copying the image to the clipboard. I believe to Copy the image would be to have it as the selected image, then call ExecWB with OLECMDID_COPY. There's a selection property available, but before that:

    DragonBoy, do you have more info on this "image"? Did you look at the page source? Any meaningful tags inside the IMG tag like Alt or Width and height? We need a viable method of locating the Image on the page. It would pointless to loop through the image elements when we dont know what to look for. Can you post the relevant source of the page? Can common sense overcome this, like it's a tiny tiny image? LOL I just need more info.

    Quote Originally Posted by westconn1
    i believe that urldownloadtofile will get the image form cache if it exists there, but testing is a bit difficult, generally people always want to get the latest version and bypass the cache
    I kinda doubt it. There a function for cache known as:
    vb Code:
    1. Private Declare Sub URLDownloadToCacheFile Lib "URLMON.dll" (ByVal lpunknown As Long, _
    2.                                   ByVal lpcstr As String, ByVal lptstr As String, ByVal dword As Long, _
    3.                                   ByVal dword As Long, ByRef TLPBINDSTATUSCALLBACK As LPBINDSTATUSCALLBACK)
    Last edited by Xiphias3; Sep 10th, 2009 at 08:12 AM.

  14. #14
    Frenzied Member
    Join Date
    Mar 2009
    Posts
    1,182

    Re: Saving web page temporarily

    See last post in this thread to copy image to clipboard...(Please note references in thread...)

    http://www.vbforums.com/showthread.php?t=570025

    As for using URLDownloadToFile, sometimes, even if you specify it to get the latest copy, it will read from the cache, so what you would have to do is DeleteURLCacheEntry API...

    http://vbnet.mvps.org/index.html?cod...ilenocache.htm


    Good Luck
    Option Explicit should not be an Option!

  15. #15

    Thread Starter
    Lively Member
    Join Date
    Jul 2009
    Posts
    76

    Re: Saving web page temporarily

    idk how this post got posted :/
    Last edited by DragonBoy; Sep 10th, 2009 at 10:34 AM.

  16. #16

    Thread Starter
    Lively Member
    Join Date
    Jul 2009
    Posts
    76

    Re: Saving web page temporarily

    westconn1:Thanks..i did try your coding on other site and it does saves the images but can't work on the web page i want it to cause it does it by downloading the image again from the server which i can't in this case

    Have a look at the source code i'm pasting and tell me what i can do about it

    vb5prgrmr:That's really helpfull..I didn't try it on the web page i'm trying to download image from but on yahoo...It's picture box shows me all the images one by one but how can i make it stop on the image i want to save ??


    Xiphias3:Same thing..i can't download the image again from the server.
    A simple right click on that image-->Save picture as...does save the image but i want it to be automatic so that the user can work while it runs on its own

    And ofcourse..here is the source codeIt's a validation image in an online game.It's generaly easy but i need to save the image that comes up every time i go to that page)
    Since the source is long..I'll use two posts to put it up..hope you can help me out.I've tried so many things but nothing seems to work here
    Last edited by DragonBoy; Sep 13th, 2009 at 10:07 AM. Reason: this much soruce code wasn't needed.

  17. #17

    Thread Starter
    Lively Member
    Join Date
    Jul 2009
    Posts
    76

    Re: Saving web page temporarily

    Here is the remaining half of the source code of that page :

    (Really hope you can help me cause i've tried everything i know to download it but it's been useless..I want to make this automatic so that the user doesn't has to do anything with it and he can do whatever he want's to do while this browser saves the image automatically)
    Last edited by DragonBoy; Sep 13th, 2009 at 10:07 AM.

  18. #18
    Addicted Member Xiphias3's Avatar
    Join Date
    Jan 2009
    Location
    Clarendon, Jamaica
    Posts
    188

    Re: Saving web page temporarily

    Quote Originally Posted by vb5prgrmr View Post
    See last post in this thread to copy image to clipboard...(Please note references in thread...)

    http://www.vbforums.com/showthread.php?t=570025
    I see now, IHTMLControlRange is what's required.


    Quote Originally Posted by vb5prgrmr View Post
    As for using URLDownloadToFile, sometimes, even if you specify it to get the latest copy, it will read from the cache, so what you would have to do is DeleteURLCacheEntry API...

    http://vbnet.mvps.org/index.html?cod...ilenocache.htm

    Good Luck
    Good stuff! Thankx!

    @DragonBoy

    OK. Well I was expecting you to post just the relevant parts:
    Quote Originally Posted by Xiphias3
    Any meaningful tags inside the IMG tag like Alt or Width and height?
    However, based on what you said:
    Quote Originally Posted by DragonBoy
    It's a validation image in an online game.
    I believe this is what i need. What I really wanted is in Bold and Underline.
    Code:
    
    <form action="/bonus.php" method="POST"><p class="center">Combination:<br /><img src="validate_image.php?id=907af914b95a0fc33c3f33bf6b4f1ec9f4b5c8207f8fc29522efe783d" 
    alt="Validation Image" /></p><p class="center"><input type="text" name="Validate" 
    size="6" maxlength="6" /><br /><input type="submit" value="Enter Combination!" /></p>
    </form>
    So, based on vb5prgrmr's post, I might have a solution. Lemme go type something.

  19. #19

    Thread Starter
    Lively Member
    Join Date
    Jul 2009
    Posts
    76

    Re: Saving web page temporarily

    Xiphias3:Yah,i was thinking i have posted a bit long source code xD.

    But anything that can help me out here would be a life saver cause i'm really tired of trying this myself even though you guys have helped me alot here at VBforums

  20. #20
    Addicted Member Xiphias3's Avatar
    Join Date
    Jan 2009
    Location
    Clarendon, Jamaica
    Posts
    188

    Re: Saving web page temporarily

    No problem. Navigate to whatever page you need to and debug the code looking at the alt properties and stuff.

    In the Form:
    vb Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.     Dim oEle As IHTMLElement, oImgEle As IHTMLImgElement, _
    5.         oHTMLDoc As HTMLDocument, oCR As IHTMLControlRange, _
    6.         oNavNWait As cX3WebBrowserNavAndWait
    7.    
    8.     Set oNavNWait = New cX3WebBrowserNavAndWait
    9.     Call oNavNWait.navigateAndWait(WebBrowser1, "www.yahoo.com")
    10.     Set oHTMLDoc = WebBrowser1.Document
    11.    
    12.     For Each oEle In oHTMLDoc.getElementsByTagName("IMG")
    13.         Set oImgEle = oEle
    14.         If (LCase(oImgEle.alt) = LCase("Validation Image")) Then
    15.             Set oCR = oHTMLDoc.body.createControlRange()
    16.             Call Clipboard.Clear
    17.             Call oCR.Add(oImgEle)
    18.             If (oCR.execCommand("copy")) Then
    19.                 Set Me.Picture = Clipboard.GetData(ClipBoardConstants.vbCFBitmap)
    20.                 Call SavePicture(Clipboard.GetData(vbCFBitmap), "C:\tmp.gif")
    21.             End If
    22.             Exit For
    23.         End If
    24.     Next oEle
    25.     Set oNavNWait = Nothing
    26. End Sub
    Last edited by Xiphias3; Sep 11th, 2009 at 04:36 PM.

  21. #21

    Thread Starter
    Lively Member
    Join Date
    Jul 2009
    Posts
    76

    Re: Saving web page temporarily

    Xiphias3:High five if that works

    I'll try it out.
    Where will it be saving that image ??Which directory exactly ??

  22. #22
    Addicted Member Xiphias3's Avatar
    Join Date
    Jan 2009
    Location
    Clarendon, Jamaica
    Posts
    188

    Re: Saving web page temporarily

    "C:\tmp.gif". You may have to rename depending on the pic format.

    vb Code:
    1. Call SavePicture(Clipboard.GetData(vbCFBitmap), "C:\tmp.gif")

    As I said, Debug first.
    Also, the Form's Picture will also be set:
    vb Code:
    1. Set Me.Picture = Clipboard.GetData(ClipBoardConstants.vbCFBitmap)

  23. #23
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Saving web page temporarily

    @ Xiphias3
    Set oCR = oHTMLDoc.body.createControlRange()
    Call Clipboard.Clear
    Call oCR.Add(oImgEle)
    If (oCR.execCommand("copy")) Then
    that was what i couldn't figure out at all, very nice
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  24. #24
    Frenzied Member
    Join Date
    Mar 2009
    Posts
    1,182

    Re: Saving web page temporarily

    Okay, see post #3 of that same thread I pointed you to. I believe you said you know the url of the image you are wanting so you could use .href or perhaps .url in the do loop to test to see if the image is the one you are after.



    Good Luck
    Option Explicit should not be an Option!

  25. #25
    Addicted Member Xiphias3's Avatar
    Join Date
    Jan 2009
    Location
    Clarendon, Jamaica
    Posts
    188

    Re: Saving web page temporarily

    Quote Originally Posted by vb5prgrmr
    Okay, see post #3 of that same thread I pointed you to. I believe you said you know the url of the image you are wanting so you could use .href or perhaps .url in the do loop to test to see if the image is the one you are after.

    Good Luck
    Quote Originally Posted by DragonBoy
    Xiphias3:Same thing..i can't download the image again from the server.
    Well, it would not work as the image isnt stored on the server or something, which is why we resorted to copying the image to the Clipboard using the code you provided in the link. Still waiting on the results of Post #20 in this thread.

  26. #26

    Thread Starter
    Lively Member
    Join Date
    Jul 2009
    Posts
    76

    Re: Saving web page temporarily

    @vb5prgrmr
    That's the problem,I don't know it's url since it's not stored on the server and hence doesn't has a fixed url.

    @Xiphias3
    I am already using a set of coding in which i have to integrate this coding,let me just post it here to give you an idea :

    I tried to integrate your coding but it gave me an error :
    Code:
    Compile error:
    
    User defined type not defined

    On each of these types:


    Code:
    Dim oEle As IHTMLElement
    Dim oImgEle As IHTMLImgElement
    Dim oHTMLDoc As HTMLDocument
    Dim oCR As IHTMLControlRange
    Dim oNavNWait AscX3WebBrowserNavAndWait
    Last edited by DragonBoy; Sep 13th, 2009 at 10:08 AM.

  27. #27
    Frenzied Member
    Join Date
    Mar 2009
    Posts
    1,182

    Re: Saving web page temporarily

    Does it have a tag of any sorts besides image (img) perhaps a name? If so you could use that to isolate it in the for each loop. Another way if it is in the same position all of the time then you might be able to use an integer to count the iterations to isolate the image.



    Good Luck
    Option Explicit should not be an Option!

  28. #28

    Thread Starter
    Lively Member
    Join Date
    Jul 2009
    Posts
    76

    Re: Saving web page temporarily

    vb5prgrmr:here is the whole image source code from the page source code for you :

    And yes,it's position is always same on every occasion
    How can i use that property of this image ??
    I however did try and cut/copy that portion from the webpage but the coding only gets longer and longer that way and it still requires me to use my mouse then...

    Even if i can't save this image..can i atleast load it on a picturebox in my form ???
    If yes then how ??
    Last edited by DragonBoy; Sep 13th, 2009 at 10:09 AM.

  29. #29
    Addicted Member Xiphias3's Avatar
    Join Date
    Jan 2009
    Location
    Clarendon, Jamaica
    Posts
    188

    Lightbulb Re: Saving web page temporarily

    Quote Originally Posted by DragonBoy
    On each of these types:
    Code:
    Dim oEle As IHTMLElement
    Dim oImgEle As IHTMLImgElement
    Dim oHTMLDoc As HTMLDocument
    Dim oCR As IHTMLControlRange
    Dim oNavNWait As cX3WebBrowserNavAndWait
    OK, let's backup. Are you telling me you havent referenced to the HTML Obj API? How do you survive without intellisense from dot-notation? In any case, you should have some version of the HTML API on your system. Do the following:

    1) Goto Project (in menu bar) -> References -> "Microsoft HTML Object library" (Syste32\MSHTML.TLB).
    Type-Libraries are used to make the programmer's life easier and are not required at run-time. They're used to allow VB to access external elements such as Interfaces(IStream from Edanmo's OLE TLB) and DataTypes (IHTMLDocument from the MS HTML TLB).

    2) Add the cX3WebBrowserNavAndWait to your project. it is attached.
    Attached Files Attached Files
    Last edited by Xiphias3; Sep 11th, 2009 at 04:48 PM. Reason: Uploaded wrong file

  30. #30
    Frenzied Member
    Join Date
    Mar 2009
    Posts
    1,182

    Re: Saving web page temporarily

    something like...
    Code:
    Dim Pic As Object
    For Each Pic In WB.Document.Images
      If Pic.alt = "Validation Image" Then
        '...copy code

    Good Luck
    Option Explicit should not be an Option!

  31. #31

    Thread Starter
    Lively Member
    Join Date
    Jul 2009
    Posts
    76

    Re: Saving web page temporarily

    @vb5prgrmr
    I'm gonna try it once again then i think..Thanks D:

    @Xiphias3
    LoL,yah,i'm a beginner in VB and all this is kinda new to me xD
    Anyways..
    Done the first step.
    Copied the class module to my Project and copied some of it's coding into the coding of my Form1(the form with the browser)

    And the format of the image is Bitmap...



    I think you are just about there to solve my problem.Just help me out on this one
    Last edited by DragonBoy; Sep 13th, 2009 at 10:09 AM.

  32. #32
    Addicted Member Xiphias3's Avatar
    Join Date
    Jan 2009
    Location
    Clarendon, Jamaica
    Posts
    188

    Re: Saving web page temporarily

    hmmm..... I have little time now, so..... post of a pic of the Local variables.
    When the error pops up, Break the code via Ctrl + Break on ur keyboard
    Go to view and click Locals
    Up a pic of the locals variables, as I cant really tell what's going on in your code.

  33. #33

    Thread Starter
    Lively Member
    Join Date
    Jul 2009
    Posts
    76

    Re: Saving web page temporarily

    Should i send a attachment of my coding to you so that you can simply see what's going wrong ?
    I'm sure something only small is bothering me right now and you can easily fix it in a sec ?

  34. #34
    Fanatic Member
    Join Date
    Oct 2007
    Posts
    544

    Re: Saving web page temporarily

    I made a function for that. However, things go wrong.

    Public Function imgToFile(img As HTMLImg, affiliateprogramid As Long) As String
    Dim ocr As IHTMLControlRange
    Dim theFile As String

    theFile = trim(CStr((GetTickCount Mod 100000))) + ".jpg"


    Set ocr = img.Document.body.createControlRange
    Clipboard.Clear
    ocr.Add img
    ocr.execCommand "copy" '<- It doesn't get copied
    Call SavePicture(Clipboard.GetData(ClipBoardConstants.vbCFBitmap), theFile)
    imgToFile = theFile
    End Function

    So where did I do wrong?

  35. #35
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Saving web page temporarily

    what exactly is being passed as img?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  36. #36
    Fanatic Member
    Join Date
    Oct 2007
    Posts
    544

    Re: Saving web page temporarily

    The html image element

    This code works though

    Public Function imgToFile(img As HTMLImg) As String
    Dim ocr As IHTMLControlRange
    Dim theFile As String

    theFile = trim(CStr((GetTickCount Mod 100000))) + ".jpg"

    'Set img = ias.findAnElement(dw1.body, "src", "https://mail.google.com/mail/help/images/logo2.gif")
    Set ocr = img.Document.body.createControlRange
    Clipboard.Clear
    ocr.Add img
    ocr.execCommandShowHelp ("Copy")
    SavePicture Clipboard.GetData(ClipBoardConstants.vbCFBitmap), theFile
    imgToFile = theFile
    End Function

  37. #37
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Saving web page temporarily

    ocr.execCommand "copy"
    did you try brackets around "copy" as per the original code posted?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  38. #38
    Fanatic Member
    Join Date
    Oct 2007
    Posts
    544

    Re: Saving web page temporarily

    I tried both.

    I think changing to execCommandShowHelp is the one that does the trick somehow. I figured this out through sheer luck. I don't even know what execCommandShowHelp does help?

  39. #39
    Fanatic Member
    Join Date
    Oct 2007
    Posts
    544

    Re: Saving web page temporarily

    Can URLDownloadToFile use proxies?

    execcommandshowhelp works most of the time. But after a while it simply fail to copy for no know reason. Only if I actually logged in it works. So if I switch to another user and let my program run it doesn't. Well, sometimes it does, sometimes it doesn't.

    Using execcommand without help will make ie pops out a message saying whether I will allow website to copy clipboard.

  40. #40
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Saving web page temporarily

    try execcommand("copy", false)
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Page 1 of 2 12 LastLast

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