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
 How to call labtalk code?

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
EigenGoofy Posted - 06/16/2011 : 08:39:05 AM
Origin Ver. and Service Release (Select Help-->About Origin): 8.5


For example, I have the following code:

del col(C);
wks.addcol(C);
col(C)[C]$="sum/N";



The Origin help files said that if wanna call this, then the code must start with (for instance): void myfunc(), so I added:

void myfunc()
del col(C);
wks.addcol(C);
col(C)[C]$="sum/N";


then in the script window, I type "myfunc", but "Command error" appears.

Question:
So How do I call the code please?

Thank You!

9   L A T E S T    R E P L I E S    (Newest First)
cpyang Posted - 06/21/2011 : 07:56:45 AM
Yes, for basically a procedure, you are better off using ogs sections.

Functions are useful when you need a return value, and when you need to pass in arguments that are not easy to achieve with %1 %2 etc.

CP
EigenGoofy Posted - 06/20/2011 : 9:50:54 PM

[Main]
del col(C);
wks.addcol(C);
col(C)[C]$="sum/N";

Save this code as "func2.ogs" in my User Files folder.

Then in the script window type "run.section(func2, Main)".

Yes, yes, this works even more convenient.

Thank you very much,SteffenG and cpyang!
cpyang Posted - 06/17/2011 : 08:16:02 AM
We greatly appreciate EigenGoofy's sharing of info and we will work on fixing that wiki page.

One thing definitely true is that ogs file name should not be the same as LT Function name since ogs files in user folder can be executed by name (calling the [main] section if present), see

http://wiki.originlab.com/~originla/wiki/index.php?title=Script:From_Files#Running_an_OGS_File

But one key think not mentioned in that wiki is that spaces in the ogs file name is striped, so the myfunc will execute "my func.ogs".

We can certainly change the precedence order to allow LT function higher precedence to avoid this confusion in future versions.

CP
SteffenG Posted - 06/17/2011 : 04:53:03 AM
If you want to use OGS-files you have to take the run.section-method. You will find help for this in the LabTalk-Help under topic 'run'.

Best regards,
Steffen


quote:
Originally posted by EigenGoofy

Hello, SteffenG

This can not work.

Save the following code as "my func.ogs":
function myfunc(){
del col(C);
wks.addcol(C);
col(C)[C]$="sum/N";
}


then in the script window, type "myfunc".

it returns "Command error".

Thank You!



EigenGoofy Posted - 06/16/2011 : 9:31:49 PM
By the way, based on my last post, the following address provides insufficient help:

http://wiki.originlab.com/~originla/wiki/index.php?title=LabTalk:Data_Types_and_Variables#Forcing_Global_Scope

EigenGoofy Posted - 06/16/2011 : 5:23:29 PM
quote:
Originally posted by cpyang

In order to define functions in an OGS and use in other places, you need to add the @global=1 before the function is defined. See

http://wiki.originlab.com/~originla/wiki/index.php?title=LabTalk:Data_Types_and_Variables#Forcing_Global_Scope


CP




It works, Thank You, cpyang!

Actually, you only give me a PARTIAL answer. There are at least 3 unsolved problems. Luckily, I solved all of them

If saving the following code as "myfunc.ogs" in the folder User Files

@global=1;
function myfunc(){
del col(C);
wks.addcol(C);
col(C)[C]$="sum/N";
}

then type "myfunc" in the script window, it will return "command error".

Solution: after saving this code as an ogs file, we have to completely exit Origin, before calling the function in the script window, otherwise it won't work.


After rebooting Origin, then in the script window type "myfunc", it does not appear "command error", but just nothing happens. type "myfunc" again, nothing happens again.

Solution: This is a naming problem, we can not name the file as the same as the name of the calling function. Let's rename "myfunc.ogs" by "myfunc1.ogs".


Aftering restarting Origin again, type "myfunc" in the script window. it appears "command error".

Solution : we have to type "myfunc1" first, at this time, it does not return "command error", then type "myfunc", up to now, it successfully calls my function!

Thank You again, cpyang!
cpyang Posted - 06/16/2011 : 1:03:47 PM
In order to define functions in an OGS and use in other places, you need to add the @global=1 before the function is defined. See

http://wiki.originlab.com/~originla/wiki/index.php?title=LabTalk:Data_Types_and_Variables#Forcing_Global_Scope


CP
EigenGoofy Posted - 06/16/2011 : 10:21:23 AM
Hello, SteffenG

This can not work.

Save the following code as "my func.ogs":
function myfunc(){
del col(C);
wks.addcol(C);
col(C)[C]$="sum/N";
}


then in the script window, type "myfunc".

it returns "Command error".

Thank You!




quote:
Originally posted by SteffenG

Hello EigenGoofy,

you have to enter first the keyword 'function' and put the code of the function inside brackets like:
function myfunc(){
del col(C);
wks.addcol(C);
col(C)[C]$="sum/N";
}

The keyword 'void' does not exist in LabTalk.

Best regards,
Steffen

SteffenG Posted - 06/16/2011 : 09:33:46 AM
Hello EigenGoofy,

you have to enter first the keyword 'function' and put the code of the function inside brackets like:
function myfunc(){
del col(C);
wks.addcol(C);
col(C)[C]$="sum/N";
}

The keyword 'void' does not exist in LabTalk.

Best regards,
Steffen

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