Monday, November 08, 2010 at 12:02 AM.
system.verbs.apps.uBASE.examples.reportStates
<<build a list of states and their capitals from the database
<<JWB Apr 93. Under Frontier Runtime™, the list goes into a TeachText document
<<but first, into a table at scratchpad.stateCapitals, so we can sort it easily
if Frontier.isRuntime () { <<create the table
new (tableType, @scratchpad.stateCapitals)}
else { <<create the outline, open it in a window
new (outlineType, @scratchpad.stateCapitals);
target.set (@scratchpad.stateCapitals);
editMenu.setFont ("Geneva");
editMenu.setFontSize (9);
Frontier.bringToFront (); <<so you can watch the outline being built
edit (@scratchpad.stateCapitals)};
local (fnum);
bundle { <<start up uBASE, open the file
local (ubasefolder);
ubase.launch ();
ubasefolder = file.folderFromPath (ubase.appinfo.path);
fnum = ubase.openFile (ubasefolder + "States Database")};
bundle { <<visit all the records in the database
local (recordCount, dir, key, i, x);
recordCount = ubase.CountRecords (fnum);
if not Frontier.isRuntime () {
op.setLineText ("There are " + recordCount + " state capitals in the database. They are:");
dir = right}; <<first headline is inserted to the right
key = ubase.getFirstRecord (fnum);
for i = 1 to recordCount {
ubase.lookupRecord (fnum, key, @x);
if Frontier.isRuntime () {
scratchpad.stateCapitals.[key] = key + ", " + x.capi + ", " + x.abbr}
else {
op.insert (key + ", " + x.capi + ", " + x.abbr, dir);
dir = down}; <<subsequent headlines inserted down
key = ubase.getNextRecord (fnum, key)}};
if Frontier.isRuntime () { << create and launch the report file, delete the temporary table
local (path, ix);
bundle { << Prepare up file
path = file.folderFromPath (uBASE.appInfo.path) + "State Capitals Test";
file.new (path);
file.setCreator (path, 'ttxt');
file.setType (path, 'TEXT')};
file.writeLine (path, "There are " + sizeof (scratchpad.stateCapitals) + " state capitals in the database. They are:");
for ix = 1 to sizeof (scratchpad.stateCapitals) {
file.writeLine (path, scratchpad.stateCapitals[ix])};
file.close (path);
try {
launch.anything (path)}
else {
dialog.alert ("Sorry...could not open your new file " + path)};
delete (@scratchpad.stateCapitals)}
else { << clean up and sort the outline
op.sort ();
op.firstSummit ();
window.zoom (@scratchpad.stateCapitals);
target.clear ()};
ubase.closeFile (fnum)
This listing is for code that runs in the OPML Editor environment. I created these listings because I wanted the search engines to index it, so that when I want to look up something in my codebase I don't have to use the much slower search functionality in my object database. Dave Winer.