PDA

View Full Version : Create tables on the fly


AlanZhang
08-24-2007, 06:01 PM
I did not find a Flexsim command to create a Global table on the fly. I write a user command to accomplish this. Here is the command:

createGlobalTable(string tableName,num row, num col, num dataType, num reset)

PARAMETERS:
tableName - table name
row - number of rows
col - number of columns
dataType - data type of the table, see settablesize()
reset - 1, clear on rest; 0, no clear on reset

EXAMPLE:
createGlobalTable("mytable",2,4,1,1)

CODE:
string tableName = parstr(1);
int row = parval(2);
int col = parval(3);
int dataType = parval(4);
int reset = parval(5);
pt("createTable ");pt(tableName);pt("\t");pd(row);pt("\t");pd(col);pt("\t");pd(dataType);pt("\t");pd(reset);pr();

if(content(reftable(tableName))!=0){
pt(tableName);pt(" already exists!");pr();
}else{
createinstance(
node("/GlobalTable",library()),
node("/Tools/GlobalTables",model())
);
setnodename(last(node("/Tools/GlobalTables",model())),tableName);
settablesize(tableName,row,col,dataType,0);
setvarnum(last(node("/Tools/GlobalTables",model())),"initonreset",reset);
updatetoolsmenu(); // add the table into Tools menu
}