76
Programming with TIDE
©2000-2008 Tibbo Technology Inc.
4.2.8.1
Embedding Code Within an HTML File
Understanding the Scope of Variables
, each HTML file has a
special scope, and all code within the file resides within this scope.
To begin a block of Tibbo Basic code within an HTML file, you must use an escape
sequence -- <? . To close the section of code, use the reverse escape sequence --
?> .
When the embedded HTTP server receives a GET (or POST) request, it begins to
output the requested HTML file. It simply reads the HTML file from top to bottom,
and transmits its contents with no alteration. However, the moment is encounters
a block of Tibbo Basic code, it begins executing it.
Tibbo Basic code inside HTML files does not differ from the code in "basic" files, but
it may not contain procedures. This is because the Tibbo Basic code in the HTML
file is considered to constitute a procedure in itself. Notice, that all code in one
HTML file is considered to be a single procedure, even if there are several
fragments of code in this HTML file. Consider this example:
<!DOCTYPE HTML
public
"-//W3C//DTD W3 HTML//EN">
<HTML>
<BODY>
BEGINNING OF OUTPUT<br>
<?
'<--------------- BASIC procedure starts here
dim
i
as
integer
for
i = 1
to
10
?>
<i> Foo </i> <br>
<?
next
i
'<--------------- procedure ends here
?>
<br>
end
OF OUTPUT<br>
</BODY>
</HTML>
There two code fragments, yet they both form one procedure. For example,
variable i declared in the first fragment is still visible in the second fragment.
The fact that entire code within each HTML file is considered to be a part of a
single procedure has implications in the way events are handled (reminder: there
is a
for all events). The next event waiting in the event queue
won't be executed until the end of the HTML procedure is reached. Just because
the HTML procedure consists of two or more fragments does not mean that other
events will somehow be able to get executed while the HTTP server outputs the
static data between those fragments ("<i> Foo </i> <br>" in our example). Use
if you want other event handlers to squeeze in!
Tibbo Basic code in the code fragments may include
that may cause various segments of HTML code to be output more
than once, to be skipped altogether, or to be output only when certain conditions
are true or false. In the above example the line "<i> Foo </i> <br>" will be
output 10 times because this line resides between two code fragments that
57
7
68
67
68