More scripts: Vector
Syntax Highlighing:
comments, key words, predefined symbols, class members & methods, functions & classes
# attach.sml
#demostrates the TableReadAttachment, TableWriteAttachment, and TableExists database functions
clear();
class VECTOR V;
class DATABASE db;
class DBTABLEINFO table;
array numeric xPoints[10], yPoints[10];
GetOutputVector(V, "VectorToolkit");
#add some points to output vector
VectorAddPoint(V, 0, 0); #element 1
VectorAddPoint(V, 100, 100); #element 2
db = OpenVectorPointDatabase(V); #open vector point database
table = TableCreate(db,"the_table","the description"); #create a new table in database
TableAddFieldInteger(table,"the_field",10); #add a new integer field in new table
TableNewRecord(table,99); #record 1 #add three new records to the field
TableNewRecord(table,101); #record 2
TableNewRecord(table,33); #record 3
array numeric records[1];
records[1] = 1; #attach record 1 to element 1
TableWriteAttachment(table,1,records,1);
records[1] = 2; #attach record 1 to element 2
TableWriteAttachment(table,2,records,1);
records[1] = 3; #attach record 3 to element 1
TableWriteAttachment(table,1,records,1); #can optionally specific the type of element to attach to
if (TableExists(db,"the_table") > 0) { #we know table exists since we made it but demostrates the function
numeric i, j;
for i = 1 to NumVectorPoints(V) {
numeric numRecords = TableReadAttachment(table,i,records);
printf("%d Records attached to element %d:",numRecords,i);
for j = 1 to numRecords {
printf(" Record Number %d has the value of %d",records[j], TableReadFieldNum(table,"the_field",records[j]));
}
printf("\n");
}
}
if (TableExists(db,3) < 0) { #
printf("There is no third table in the database");
}