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
 Multiple outputs in user-defined functions

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
JokerOne Posted - 02/10/2016 : 04:54:57 AM
Origin Ver. 9.1 and Service Release 1 (Select Help-->About Origin):
Operating System: Win 7

I am quite new to LabTalk and still struggling a bit.
Anyway, although this question was probably stated before, and I just could not find it by searching, I kindly request help for the following:

Is it possible to define LabTalk function that result in more than one output argument? And, if possible, could these multiple output be of different types, e.g. strings, numeric, etc. variables?
like:
function [???int,string] FindColbyShortName(string ColShortName$)
// find a coloumn of the active worksheet with the shortname provided
// return the longname of this coloumn
// also return the first (numeric) entry in this colum


Could you provide a dummy code for me?

The code above is just meant as an example, I am about to create more complex functions that return more than two return values, etc., as far is such a thing was possible in Lab Talk.

Thanks for your help.

7   L A T E S T    R E P L I E S    (Newest First)
JokerOne Posted - 02/12/2016 : 03:25:41 AM
Ok, thanks for the info.

The manual is a bit unprecise here, anyway. E.g. as far as I noticed so far, you can use range variable as input as least, while this is not stated (but an example code is given, etc.).
Nevermind, that is not too bad.

I will work with the (ref tree ...)-solution. Thanks for your help!
cpyang Posted - 02/11/2016 : 8:41:34 PM
It must be that we had Tree return support at one point but not working too well and later when we clean up the code, we did not finish with it. We can look into making this to work on this year's release.

CP
JokerOne Posted - 02/11/2016 : 12:13:39 AM
quote:
Originally posted by cpyang

I am afraid LabTalk function does not support tree as a return object, so you have to use the ref method as you had confirmed.

CP




Thanks, for your answer!

I am fine to accept that. However, the docs say:
(http://www.originlab.de/doc/LabTalk/guide/Functions)

"Both arguments and return values support string, double, int, dataset, and tree data types. "

So, I am still wondering, if this might be possible, or if the docs are wrong considering this point?

cpyang Posted - 02/10/2016 : 11:59:14 AM
I am afraid LabTalk function does not support tree as a return object, so you have to use the ref method as you had confirmed.

CP
JokerOne Posted - 02/10/2016 : 11:18:13 AM
Here is an update of my struggling:

The following kinda works, however appears quite strange to me:

function int tree_function(ref tree aa)
//

{

aa.c = 3;
aa.d$ = "A String";
return 1;
}

>>tree ee
>>cc = tree_function(ee)
>>cc =
cc=1
>>ee.=
C = 3.
D = A String

I would prefer a syntax that some works as stated in my previous post. I should be very happy, if anybody might let me know, if this is possible or not.
Thanks all
JokerOne Posted - 02/10/2016 : 10:49:43 AM
Thank you very much for your answer.

I will try your code and see, if I can adopt this concept.

However, meanwhile, I came across the tree-concept in LabTalk, which I believed is what I am looking for.

I tried the following:

function tree tree_function(double a)
//

{
tree b;
b.c = 3;
b.d$ = "A String";
return b;
}

Now, I hope, that calling, e.g.

d = tree_function(1)
would result in:
d.c = 3
d.d$ = "A String"

but unfortunately something seems to be wrong in my syntax.
As I get:

>>tree d
>>d = tree_function(1)
>>d.=
>>d.d=
d.d=--
>>d.c=
d.c=--
>>d.d$=

Could anybody help me out?
Thank you

cpyang Posted - 02/10/2016 : 10:00:12 AM
Try the following

//assume active worksheet, v1 is the first cell with value
//return 1 if found, 0 if not
Function int FindTest(string sName$, ref string sLN$, ref double v1)
{
	//unfortunately, there is no wks.findcol method
	for(int nc=1; nc<=wks.ncols;nc++)
	{
		string strName$ = wks.col$(nc).name$;
		if(strName$==sName$)
		{
			sLN$=wks.col$(nc).LName$;
			v1=wcol(nc)[1];
			return 1;
		}
	}
	return 0;
}
//now code to test it
string strCLN$;
double cell;
int nret = FindTest("B",strCLN,cell);
nret=;
strCLN$=;
cell=;


Here is the page I found the info by google,

http://www.originlab.com/doc/LabTalk/guide/Functions#Passing_Arguments_by_Reference

but it is really tricky that when calling function, string variable passing by reference must have not have the $

CP

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