The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum for Programming
 LabTalk Forum
 Detecting if LabTalk User Functions Exist

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

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.;

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000