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
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 LabTalk Forum
 Detecting if LabTalk User Functions Exist
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

cdrozdowski111

USA
247 Posts

Posted - 12/23/2012 :  09:35:29 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
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;
}

greg

USA
1378 Posts

Posted - 12/31/2012 :  10:35:47 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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.;
Go to Top of Page

cdrozdowski111

USA
247 Posts

Posted - 12/31/2012 :  2:59:09 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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.

Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000