T O P I C R E V I E W |
cdrozdowski111 |
Posted - 12/23/2012 : 09:35:29 AM OriginPro 9.0.0 (Student Version), Win7 64-bit, running in VMware Fusion 5.0.2
I want to define a user LabTalk function to be available on the session level by calling a code section to define it before using it (see code below).
Is there a way to determine if the function has already been declared for the session-level before declaring it (potentially again)?
// Script section to define user LabTalk function for session [deffunction]
// ??? First, determine if MyLabTalkFunc() already exists before defining it
@global = 1; Function int MyLabTalkFunc(string strParam) { return 1; }
|
2 L A T E S T R E P L I E S (Newest First) |
cdrozdowski111 |
Posted - 12/31/2012 : 2:59:09 PM That's a good idea. In fact, you don't even need to define a variable of the same name. The function name itself shows up globally. So you can just do the
if (ISNA(MYCUBEROOT)) {...}
using the function name itself.
Except, this technique doesn't quite work perfectly. The fist time you run it (and it is the same with the demo code Greg provided), you get an "Undefined variable: MYCUBEROOT" error in the Message Log.
|
greg |
Posted - 12/31/2012 : 10:35:47 AM I couldn't find a way testing for a function, so I guess you could adopt a methodology similar to what you might do with c files. Here I create a variable with the same name as my function (no conflict):
if(ISNA(MYCUBEROOT)) // Here is my test { ty Need to define it; @global = 1; function double MyCubeRoot(double dVar) { int MyCubeRoot = 1; if(dVar < 0) return -10^(log(abs(dVar))/3); else return 10^(log(dVar)/3); } @global = 0; } else ty Been there, done that.;
|
|
|