• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 388
  • Last Modified:

VB6 - Submit Web Form, Scan Response, Save Image to My Web Server

Yet again, a question that seems like it should have a simple answer, but I am stuck anyway.  

*** My PC is Windows XP Pro with all critical updates. ***

I want to use VB6 to:

1.  Submit a webform from my PC.  The form can be seen at:

2.  After submitting the form, scan the response from the remote webserver for the URL of an image I need (of Earth).  The URL for the image is hashed using an algorythm I don't have.   I have to read the URL out of the page source sent back by the web server.  The URL for the image is findable by searching for the <img> tag in the page source.  Example URL for image:

3.  Use the URL of the image to update the image file on my server (i.e., copy the image from the remote server to overwrite the image on my web server.)  

4.  This needs to be a background process, running every 5 minutes on my PC.  My PC has access to my web server, via FTP.

I have a web page that displays a picture of the Earth 

The problem is I want to update the picture based on the time it is being viewed (within 5 minutes of when the page is requested).  

To see what I mean, go to this page, then submit the web form at that page.  You will see a current picture of Earth, from space, with the clouds removed, showing day and night light.

I want to grab the picture off that page, then display it on my web page, so it will look something like this, depending on the date/time:

Complication:  the Earth pictures I want to use come from someone else's website.  The URLs of the pictures at that website vary with the date/time shown by the picture.  So, I need a way to capture the pictures, even though the URLs change.

I want to write a VB6 program that will, in effect, submit the web form every 5 minutes, then save an updated version the Earth picture onto my web server, so my web page can display it.  

I have written VB6 programs to do things along this line, but it's been a few years.  Additionally, I don't have access to the source code I did those years ago.

I need someone to tell me which objects I need to use in VB6 to get the picture update program working.   For instance, is there an object I can use to submit a web form, then scan the web page source coming back in response, without displaying the web page in a browser?

This PDF file lays out the path I am trying to follow, along with more detail on where the complications exist.

Any assistance in working through this problem will be appreciated immensely.  

I'll add points to the question (or open sub questions) to reward various people contributing, assuming that happens.  If someone can step me through this, I would think 200-300 points would be in order.  I am starting low on points, in case I need to open new questions to get this problem solved.  I have no problem adding points as warranted.

Thank  you in advance.
  • 2
1 Solution
It's not too hard.  One way is to use the Inet control (Microsoft Internet Transfer Control), this should do it.  Obviously you want to change the parameters used to get the image as required.

    Dim PostData As String
    Dim result As String
    Dim i As Integer
    Dim j As Integer
    Dim imageURL As String
    Dim Image() As Byte
    'Get the page that contains the image link
    PostData = "imgsize=320&;opt=-l&;lat=22.125&;ns=North&;lon=99.625&;ew=West&;alt=148024950&;img=learth.evif"
    Inet1.Execute "http://www.fourmilab.ch/cgi-bin/Earth?" & PostData
    While Inet1.StillExecuting
    result = Inet1.GetChunk(10000)
    'find the image link
    i = InStr(1, result, "/cgi-bin/Earth?di=")
    j = InStr(i, result, """")
    imageURL = Mid(result, i, j - i)
    'Get the image itself
    Inet1.Execute "http://www.fourmilab.ch/" & imageURL
    While Inet1.StillExecuting
    Image = Inet1.GetChunk(1000000, 1) ' in actuality it only gets the number of bytes in the image
    'save it to a file
    Open "C:\test\earth.jpg" For Binary Access Write As #1
    Put #1, , Image()
    Close #1

Oh, to post it to your server, you would do something like this

    Inet1.url = "ftp://<yourFTPSite>"
    Inet1.UserName = "<yourusername>"
    Inet1.Password = "<yourpassword>"
    Inet1.Execute , "PUT C:\test\earth.jpg <YourFTPFolder>\earth.jpg "
    While Inet1.StillExecuting
    Inet1.Execute , "QUIT"
DanimalAuthor Commented:

If I get stuck or have followon questions, I will let you know.  In the meantime, thank  you....
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now