Every programmer involved with the Internet will be aware of Ajax (Asynchronous Javascript and XML), but they may not realize that the techniques involved are not limited to Javascript alone - the techniques can also be used, for example, with VBScript; and this raises an interesting possibility - the ability to use the Ajax technique to create a Windows Desktop application.
All that's needed for the Ajax technique to work with VBScript is:
- VBscript to be installed (but fortunately that comes as standard on every Windows pc)
- the XML HTML request object to be installed (again that's built into every Windows computer)
- a server script (on an web or network server)
- a VBScript that will send data to the server and then process the data returned by it
In this example:
- a PHP script on the server will take a company acronym as an input and return the current stock quote from Yahoo! Finance
- the VBScript code will call the PHP script on the server and then display the result
The first step, therefore, is to set up the PHP script on the server.
Setting up the Server Side of the Application
In the final application the VBScript will call a PHP script and, as with any code, that script should (wherever possible):
- consist of a set of functions allowing the code to be reused as required
- store the functions in libraries - again allowing the code to be reused
And the PHP library for this application will look like:
If the script has been saved in a library (named, for example, yahoo_library.php) then it can be called from a PHP script (and it's this PHP script that will be called from VBScript):
Testing the Server Side of the Application
Before going any further it's a well to test the PHP script - and all that's needed for that is to enter the correct url into a web browser; and that url must contain a valid Yahoo! Finance company acronym; so, if the PHP script has been saved as yahoo_stock.php then the url will be something like:
The resulting web page will display the current stock quote for Novell Inc.
The Yahoo! Finance VBScript Client Application
All of the hard work has now been done (mainly by Yahoo! Finance) and so all that's left to do is to write a simple piece of VBScript that will:
- accept an input from a user
- format a url and sent it to the server
- show the user the results
This can easily be accomplished in a few lines of code:
Running the Yahoo! Finance VBScript Client Application
If the VBScript is saved as yahoo.vbs then it can be run in either of two ways:
- open up Windows Explorer and double click on the yahoo.vbs icon
- open the MS-DOS Prompt and use cscrip to run yahoo.vbs, for example:cscript /nologo yahoo.vbs rht
Conclusion
This simple example shows that the Ajax technique is not the preserve of web sites, and that the same on-line sources can easily be used to create Windows Desktop applications.
Further Reading
Using Yahoo! Financial Stock Quotes
Currency Conversion with Yahoo! Finance
Accessing Yahoo! Finance from PHP