Showing posts with label table. Show all posts
Showing posts with label table. Show all posts

Tuesday, January 13, 2009

A Simple Table - Lesson 7

Run BASIC provides an easy way to display tabular information in a web app. The TABLE statement takes the data from an array and places it in a table with automatically aligned columns. Here is a simple program that lets you add a row of three items at a time to an array, and then the table grows as each row is added:

'simple table
limit = 200
dim locations$(2, limit)

[displayAll]
cls
if position <= limit then
print "Name: ";
textbox #name, ""
#name setfocus()
print " X:";
textbox #x, ""
print " Y:";
textbox #y, ""
button #add, "Add", [add]
else
print "Limit reached."
end if
if position > 0 then
table #t, locations$()
render #t
end if
wait

[add]
locations$(0, position) = #name contents$()
locations$(1, position) = #x contents$()
locations$(2, position) = #y contents$()
position = position + 1
goto [displayAll]
Here is a version for the GOTO averse. ;-)

'simple table
global #name, #x, #y, limit, position
limit = 200
dim locations$(2, limit)
call displayAll
wait

sub displayAll
cls
if position <= limit then
print "Name: ";
textbox #name, ""
#name setfocus()
print " X:";
textbox #x, ""
print " Y:";
textbox #y, ""
button #add, "Add", add
else
print "Limit reached."
end if
if position > 0 then
table #t, locations$()
render #t
end if
end sub

sub add key$
locations$(0, position) = #name contents$()
locations$(1, position) = #x contents$()
locations$(2, position) = #y contents$()
position = position + 1
call displayAll
end sub


In the next lesson we will add some visual decoration to the program.