How To send a data table as an argument into a functionHello everyone,
So I have been trying to do this for a while now and I can't get my head around it.
I'm making a script to export multiple picture from a few different folders. I have created an "import" function and a "trim" function.
Import = Function ({path},
dtimport= Multiple File Import (
// the import arguments
)<< Import Data;
Return (dtimport);
};
Trimtables = Function ({table, arg1, arg2, arg3},
table:Image<<SET name=""></SET>So it works fine until I try to send this table as argument for my trim function.
I understand that dt1 is not my actual table but just a pointer and that If i send that directly to the table the function would only have a pointer to that pointer. So I tried using :
dt1<<SET name=""></SET>
and That works fine. The issue is when I try not to use a custom title for each table. I tried the following :
Trimtables (dt1<<GET name=""></GET>
But this does not work. I tried a whole lot of variations (while changing what the function expects):
Trimtable (Char(dt1<<GET name=""></GET>
But nothing seems to work . Essentially what I would need would be like in C where you would send &datatable as argument. I'm sure this is pretty trivial but for the lfie of me I can't get my head around it.
Any ideas ?
Thanks,
Bob
Re: How To send a data table as an argument into a functionThanks Craige_Hales,
I was writing my reply when you posted yours. Good thing we came to the same conclusion 
Re: How To send a data table as an argument into a functionHi pmroz,
Thanks for the quick reply.
I have been using the Caption function, which I guess is pretty similar to Show, with the added benefit that it display over everything else instead of writing in the log which gets pretty messy as soon as there are errors.
I have made the following code, which works :
Names Default To Here( 1 );
Mydt = Function({},
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt<<SET name=""></SET>So this tells me it is indeed possible to use the data table name as a reference and work from there.
The issue is, when I try to use this code with a table created with the Multiple File Import function, then it doesn't work any more, which tells me something else is afoot.
I think when creating a table from multiple import, jmp considers the object not as a data table but as something else. When I use the get name function, it returns not a normal quoted string but a list.
It seems to be working now that I use the following in the "mydt" function :
m = dt[1] <<GET name=""></GET>
Still this feels a bit weird. Any ideas why importing multiple files leads to this behaviour ?
Re: How To send a data table as an argument into a functionMFI returns a list of the tables it opened, even if there is only one table. The result of your import function is probably a list with a single item, { datatable("pictures.jmp") } or similar. You probably need something like
TrimTable( dt1[ 1 ] )
to get the first data table from the list.
Re: How To send a data table as an argument into a functionTry putting some show statements inside your functions to see what's going on. This code snippet works OK:
fn1 = function({tbl_path},
dt_fn1 = open(tbl_path);
dt_fn1;
);
fn2 = function({tbl, arg1, arg2},
show(tbl, arg1, arg2);
tbl:height << set name("New Name");
);
dt = fn1("$sample_data\Big Class.jmp");
show(dt);
fn2(dt, "Hello", "World");
Re: How To send a data table as an argument into a functionand of course I tried this :
Trimtables (Data Table (dt1<<GET name=""></GET>
I guess the Get Name() instruction just does not return a normal string but a weird thing like "!\ "data table name" !\"
I guess in last resort I could trim that string to remove the special characters but that sounds like a desperate measure