Friday, January 2, 2009

Creating a Web Form - Lesson 2

Let's take the simple interactive hypotenuse calculator from the previous post and create a version of it that has a couple of fields and a button to do the computation:
print "Hypotenuse Calculator"
print "Length of side A: ";
textbox #sideA, a
print "Length of side B: ";
textbox #sideB, b
button #go, "Go!", [go]
if c > 0 then print "Length of side C: "; c

a = #sideA value()
b = #sideB value()
c = sqr(a^2+b^2)
goto [displayAll]
The first part of the program clears the web page using the CLS statement. Then it adds labels and entry fields using the PRINT and TEXTBOX statements.

Then the BUTTON statement adds a button that will use the code at the [go] label to compute the length of the C side.

Notice the IF THEN statement after the BUTTON statment. If the length of C is greater than zero then that means we have computed at least once, so print the result on the web page.

No comments: