Retrieve a Stock Quote in ASP

I would like to create an ASP page that returns a stock quote entered by a user. I guess that it would be using an something like PCQuote, or Yahoo Finance as an engine. How do I do that?
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

xavConnect With a Mentor Commented:
I discovered an object that MS ships with VB Pro. and Enterprise (but is undocumented anywhere in ASP) called the Internet Transfer Control.  With it, you can do what you're looking for.

<%@ language="JavaScript" %>
Inet = new ActiveXObject("InetCtls.Inet.1");
Inet.Url = urlAddress;
FileContents = Inet.OpenUrl();
aGeneralArea=FileContents.split("Last Sale");
Response.Write("Current price for "+ cTicker +" is: $"+strPrice[0]);
Do you want to simply retrieve the financial information to display it the way you want it?  Or do you simply pass the information so that the quote site displays the right page?
chicheAuthor Commented:
I want to retrieve the info to display it the way I want it. A VB Script (or JavaScript) ASP function which returns the stock price for a given ticker symbol would be fine.

Never miss a deadline with

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

I don't think you can use ASP (or javascript) alone to do this.

I would do it like this:

- Use an HTML form to obtain the stock symbol
- In VB create an Active-X control the uses the browser object to fetch the page from the data supplier
- Parse the page for the stock symbol in the Active-X control
- Pass the value back to your ASP page
- Show the results
chicheAuthor Commented:
I agree with your process, but why do I need to go through an ActiveX object? I am quiet sure that an ASP script could just as well instanciate the browser object..

My ISP will not allow me to install my own ActiveX..
The browser object *IS* an Active-X control. It's shipped with VB. It allows you to tell the browser to navigate to a page, then retrieve the output of that page as a text stream then perform whatever processing on it you need. ASP cannot fetch the contents of the browser on its own.
chicheAuthor Commented:
ok, ok. I misunderstood your comment.

when you wrote "- In VB create an Active-X control the uses the browser object ", I thought VB meant VB and not VBScript, used in ASP.

what I need is a sample of VBScript code to accomplish what you are describing with the browser object. That's the earth of the problem.

I am increasing to 150
Diodeus is right, you need some sort of server side object that can retrieve a URL as a text stream.  Since your ISP will not allow you to register your own objects, you could use a server that already has such an object.  PharLap software offers a server with several JavaScript helper objects that will let you do just that.  You can use their server to get the URL (which sends the contents down as a variable FileContents), and then parse the source of that file until you get the price.  Since it has to download the full URL from PCquote, it's not fast. It's not pretty.  But it does do the job.

Name it getQuote.asp, and use it something like this:

<% cTicker=request("cTicker") %>
<SCRIPT LANGUAGE="JavaScript" SRC="<%= cTicker %>"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
function test() {
      aGeneralArea=FileContents.split("Last Sale")
      alert("Current price for <%= cTicker %> is: $"+strPrice[0])
</head><body onLoad="test()">
<form name="frmMain" action="getQuote.asp" method="post">
Enter Ticker Symbol: <input type="text" name="cTicker" maxlength="5" size="5" value=""><br>
<input type="Submit" value="Submit">
chicheAuthor Commented:
Very interesting comment. I tried it and it works. The problem is that the "parsing" is done on the client, rather than on the server and I really want to have a server based solution. What I really need is the code that pharlap is using...

A friend showed me a very easy way to retrieve the content of an internet web site using PHP (similar to ASP) on the server:

$contents = file("");

How I do the same thing with ASP?
The parsing is done on the client because ASP does not have an inherent way of reading a URL into a variable.  Basically, if you're using ASP, you need to use some sort of object on the server as Diodeus describes.

Presumably, the ISP has IE on it, which has a webBrowser control that I believe you can access via server.createObject("dll.webBrowser"), which will do what you're looking for.  However, I'm not really sure what the proper syntax would be.  I'm sure someone else can give you the proper syntax.

P.S. You can get the source for the Parlap javascript, and java applet at:

Also remember that anytime you're using someone else's content, you need to get permission from them.  Even though it's on the web, they still have copyright protection.
chicheAuthor Commented:
"ASP does not have an inherent way of reading a URL into a variable". It's hard for me to believe but you are probably right and that makes me think that once more Microsoft is getting away with a mediocre product. How else explain it? Why would you have to instance an object to simply read an http file?

Can anyone else help me?

chicheAuthor Commented:
Thanks. That's kind of what I was looking for. It worked on my PWS. Unfortunately my host provider (IMC Online) doesn't have this control registered on their server so I can't use it. Any idea?
I'd just ask them if they have any internet browser/transfer type controls that can load another page.  If not, they probably wouldn't be too averse to registering that component, since it does come from Microsoft.  Usually, they only object to home-made controls, since they're never sure what they'll do.  But, if they're friendly, they probably wouldn't think twice about registering it (especially if you sent them the control along with the request).
chicheAuthor Commented:
Well, those guys wouldn't want to do that. I am looking for a provider that is more "flexible", the way you describe it. Look at question 
All Courses

From novice to tech pro — start learning today.