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.

1 comment:

lauragray said...

Thank you for this blog.

I have some suggestion for that topic. The most important things for that lesson are learn more about it and you need focus and to understand what you are doing and one of the main operation we should have a knowledge about it.

For more tips and information about it. Visit web programmer site.