|
|

A Quick Note About Using a Proper Editor with Webbatch Before you begin to write your first WebBatch program, while it is true that you can use any text editor you wish, I highly recommend you use the included editor, WinBatch Studio, that came with your purchase to create and modify WebBatch scripts. WinBatch Studio will color your source code based on recognized syntax and makes it much easier to program in, rather then something like Notepad. WinBatch Studio, comes with the free copy of WinBatch that you received with WebBatch. Simply install WinBatch and WinBatch Studio will install itself. |
Copyright by darkchip.com |
Your first WebBatch Program, Displaying the Current Time on a Web page I thought to start us off, I would pick something simple, yet demonstrates the concepts behind WebBatch. Let's say you wanted to have WebBatch that you wanted to display on the page the time the page was queried. Simply using static HTML pages alone, you would not be able to achieve this. Below is the WebBatch code which will output the current time each and every time the page is queried : ; WhatTimeIsIt.web ; our first WebBatch program webout('Content-type: text/html',2) webout('<html>',1) webout('<head>',1) webout('<title>What Time Is It?</title>',1) webout('</head>',1) webout('<body>',1) Now=TimeDate() webout('The current date and time is : %Now%',1) webout('</body>',1) webout('</html>',1) |
As you can see from the screenshot, a webpage is displayed showing the current date and time. Let's spend a bit of time examining how this was done. Creating the WebBatch Script (the .web file) |
First let's use WinBatch Studio to create our WhatTimeIsIt.web file, by clicking Start -> All Programs -> WinBatch -> WinBatch Studio |
(1) |
Click on File and pick New. Proceed to then type in the code above and once complete save the file as WhatTimeIsIt.web in the following directory c:\program files\webbatch\WhatTimeIsIt |
(2) |
With the code complete and stored in the c:\program files\webbatch\WhatTimeIsIt we are ready to use a browser to access the file. One thing to note here however is that all your WebBatch scripts need to be stored under the c:\program files\webbatch folder. You can store your .web files in seperate folders or simply stand alone .web files, however everything must reside under the master WebBatch folder within program files. Now to run the WhatTimeIsIt.web file, type the following in the browser on the server : http://localhost/webcgi/webbatch.exe?WhatTimeIsIt/WhatTimeIsIt.web What this is doing is that your browser is called webbatch.exe on the server and you are telling webbatch.exe to run the .web file located in a folder called WhatTimeIsIt and a file within that folder called WhatTimeIsIt.web. Webbatch.exe parses/reads the .web file and dynamically displays the output in the form of HTML (DHTML). Let's examine the code a bit closer to understand what webbatch.exe is outputting : ; WhatTimeIsIt.web ; our first WebBatch program The above code are comments noted by the ; webout('Content-type: text/html',2) webout('<html>',1) webout('<head>',1) webout('<title>What Time Is It?</title>',1) webout('</head>',1) webout('<body>',1) Standard HTML being printed to the browser. Webbatch.exe notices the command webout and immediately outputs whatever is located between " ". As you can see the contents within " " this is standard HTML that is generally seen at the top of HTML documents Now=TimeDate() A user defined variable called Now has been assigned the value of the function TimeDate(). Nothing is outputed to the browser by this command. Simply the user defined variable Now gets the value returned by calling the TimeDate() function. webout('The current date and time is : %Now%',1) With the variable Now storing the value of TimeDate, I would like to have it display its contents. I use the webout command, and the words The current date and time is get presented to the browser and the value of Now is outputed. When you want to output the contents of a variable in a Webout statement, simply enclose it between a pair of %, such as displayed with the Now webout('</body>',1) webout('</html>',1) Again Standard HTML code that you would see at the end of an HTML document. The neat thing here. is that given this script is run each time the URL is requested, the value of Now changes with each request, causing a new update paged to be generated with a new value for the date and time. What does that make? Dynamic HTML ! |