|
The intention of this example is to teach you
how to get a CGI script running on your web server.
In this example, we will develop the most basic CGI script.
Only one step consists of writing any VB code.
For specific instructions on how to find your Document Root
and CGI directory and how to point your browser at a CGI script,
jump to
Web Server Directory Mapping.
|
Step 1 - Create a new directory called vb_hello
in your web server's Standard CGI directory.
You will save all the source code for this project in this new directory.
Step 2 - Copy the VbWeb.Bas and Text.Bas modules into the new directory.
They contain all of the VBWeb source code.
Step 3 - Start Visual Basic.
It should start with a new project for you.
The Project window should only contain Form1.
Step 4 - Remove Form1.
Since the visitor gets an HTML page to see instead of a VB form,
your project does not need any forms.
You might as well remove all the custom controls too.
To remove a form, you can right click on the form listed in the Project window
and choose Remove Form or Remove File from the menu that pops up.
Step 5 - Add the VbWeb.Bas and Text.Bas modules to the project.
Be sure to add the ones you copied to the new directory.
To add a module to a VB project, choose Add File from the Project or File menu.
Step 6 - Add a new module to the project.
This module will contain all the code that is specific to this project.
To add a new module to the project,
choose Add Module from the Project or Insert menu.
Step 7 - Copy the following code and paste it
into the new module's General Declarations section.
(jump down to code explanation).
Public Sub Main()
Send CGI_CONTENT_TYPE_TEXT_HTML
Send vbCrLf
Send "Hello World!"
End Sub
Step 8 - Save the project in the new directory.
To save the project, click the picture of a diskette in VB's main toolbar.
You can give any name for the BAS module, such as Main.Bas or vb_hello.Bas.
Name the project vb_hello.bas.
Step 9 - Make an executable named vb_hello out of the project.
Be sure to make the executable in the new directory
so that your web server can execute it.
|
Workstation User Tip:
If you compile a script on a different machine from the web server,
be sure all the DLLs and other support files are also on the web server.
Jump to
Debugging for more details.
|
Step 10 - Point your browser at vb_hello/vb_hello.exe in
your web server's standard CGI directory.
The URL should look something like this.
http://127.0.0.1/cgi-bin/vb_hello/vb_hello.exe
|
About the Source Code in Hello World
The Send instruction is how you get a response to your visitors.
The idea is to send an HTML page as a response.
You could even read in the contents of an HTML file and send that.
Except for one thing;
you have to send a special header.
In the Hello World example, the literal header is:
Content-Type: text/html
followed by a blank line.
You don't see that in the source code because that header is in a constant.
It is safer to send the constant than the literal.
That way, if your code is wrong, you find out.
This is not the only header you might send
but it's the only one you will need for some time.
|

|
|

|
|
|