Solved

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

Posted on 2006-11-11
3
343 Views
Last Modified: 2008-01-16
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:  
http://207.234.222.20/299-ReleaseArea/Earth/GetUpdatedImageFromSwitzerlandGuysServer.htm

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:
http://www.fourmilab.ch/cgi-bin/Earth?di=69325F8E2A06C40BA0562BCA3DB757E0DB3326017B455D6C8A5CAF33A1CCEE9F93AC384A236275BE82DCB23054F7C2E061F8027BCFE2E64FD7C431A042E251

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.


BACKGROUND INFO
I have a web page that displays a picture of the Earth
http://207.234.222.20/299-ReleaseArea/Earth/Earth.html

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.
http://207.234.222.20/299-ReleaseArea/Earth/GetUpdatedImageFromSwitzerlandGuysServer.htm


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:
http://207.234.222.20/299-ReleaseArea/Earth/EarthExample.html

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.


PROPOSED SOLUTION
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.



HELP NEEDED
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?


MORE INFO
This PDF file lays out the path I am trying to follow, along with more detail on where the complications exist.
http://207.234.222.20/299-ReleaseArea/Earth/UpdatingProblem.pdf


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.
0
Comment
Question by:Danimal
  • 2
3 Comments
 
LVL 16

Accepted Solution

by:
JohnBPrice earned 85 total points
Comment Utility
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
        DoEvents
    Wend
    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
        DoEvents
    Wend
    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

0
 
LVL 16

Expert Comment

by:JohnBPrice
Comment Utility
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
        DoEvents
    Wend
    Inet1.Execute , "QUIT"
0
 
LVL 1

Author Comment

by:Danimal
Comment Utility
AWESOME!  THANK YOU!

If I get stuck or have followon questions, I will let you know.  In the meantime, thank  you....
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now