Creating Dynamic Web Pages with PB/CC

By Dave Navarro, Jr.

The PowerBASIC Console Compiler for Windows (PB/CC) provides the programmer with the means to interact with a form on a web page using the BASIC language. It has direct support for 32-bit STDIN and STDOUT. This means your web server communicates directly with your application and your application communicates directly with your web server. Allowing remote users or staff members to access your company's data via the World Wide Web has never been easier.

The interaction is made possible by writing a program that reads the input from a web page, placing that .EXE on your web server, and by referring to that program in the web page's HTML FORM statements. The program created with PB/CC executes CGI commands.

What is CGI?

CGI stands for Common Gateway Interface, the actual method used by a web server to "talk" with a CGI program. When a web server executes a CGI program, it captures all data sent to and from "standard I/O".

Using the STDIN keyword in PB/CC you can read the data sent to your program from a web browser form or document. You can then parse through the data, perform some kind of action (a database lookup, for example) and then use the STDOUT keyword to send data back to the browser. Typically, you would do this using the HTML language to make it look nice and pretty.

Is that all there is?

Of course, writing a complete CGI program takes a little more than just reading and writing data through standard I/O. When your program reads data from a web browser form, it is sent in a format called "URL encoding". That means certain characters which can not be sent over the internet (such as a tilde ~) are encoded into a special hex format that can be transmitted over the internet.

After the input data from the web server has been decoded, you can access the information from the different fields in your form. Each field in your form has a "name" associated with it. And the data for that field has a "value". Together, they are called "name/value pairs". For example, you may have a field name called "firstname" and a value associated with it of "denise". The web server will give them to you in the form of "firstname=denise".

Once you have decoded the data into something you can manage and you are ready to begin talking back to the web browser, you must first tell the web server what type of data you are going to send it. This is done by using the STDOUT statement to print a header. The most typical header is for HTML, so we would print "Content-type: text/html" followed by a couple of carriage return / linefeed pairs. You can then begin sending your HTML code for the rest of the page.

Because web servers can run on so many different platforms (Linux, for example), there are actually several different methods for exchanging data between a web server and a CGI application. The method described above is called the POST method, and is the most common. All known Windows web servers support the POST, GET and COMMAND methods.

PB/CC includes the complete source code to a CGI application and an HTML page with a form that you can test with your web server. It's important to note that you can not call a CGI application directly from a browser, you must call it from an HTML page on your web server. Microsoft provides the Personal Web Server (called Peer Web Server on Windows NT) with Microsoft Windows.

In addition to the example code, PB/CC includes the code necessary to support all of the CGI communications methods, handle URL decoding, and parsing your name/value pairs into an array that you can more easily access. See the PBCGI.INC file for more details.

You can find more information on HTML and creating forms at, the standards body of the World Wide Web.