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
 Forum for Origin C
 Return two values from C function
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

peter.cook

UK
356 Posts

Posted - 01/28/2004 :  2:48:10 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
HI,

Can I return multiple values from an Origin C function via Labtalk
eg I can set up

typedef struct {

string StringValue;
double RowValue;

} FindRowAndString;

FindRowAndString OCFindValueFromSheet(string WSName, int ForCol, int FromCol, string MatchString, int NumRows)
{
Worksheet wks(WSName);
string Forstring;
string Fromstring;

FindRowAndString ResultsOut;
ResultsOut.StringValue="NULL";
ResultsOut.RowValue=0;

for(int NumRow=1; NumRow<=NumRows; NumRow++) {
wks.GetCell(NumRow-1,ForCol-1,Forstring);
if(Forstring.CompareNoCase(MatchString)==0) {
wks.GetCell(NumRow-1,FromCol-1,Fromstring);
ResultsOut.StringValue=Fromstring;
ResultsOut.RowValue=NumRow;
break;
};
};

return ResultsOut;
}


and obtain either OCFindValueFromSheet.StringValue or OCFindValueFromSheet.RowValue with another C function eg

int trip()
{

int temp;
temp=OCFindValueFromSheet("HTSSIniFile",1,2,"Expt_Date",20).RowValue;
return temp;

}


thus trip()= returns 12.

Can I return eg StringValue and RowValue in LabTalk without running OCFindValueFromSheet twice?


Cheers,

Pete


Edited by - peter.cook on 01/28/2004 2:49:14 PM

cpyang

USA
1406 Posts

Posted - 01/28/2004 :  6:10:20 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Peter,

Would it be good enough to just pass values back to LT?, see below
 
// append str with number,
// then increment number
void dd(string& str, double& var)
{
str += var;
var *= 2;
}




Then in LT,

aa$=junk;xx=1;
dd aa$ xx;
aa$=; xx=;


and you should see string and numeric variables both pass back from OC into LT


CP


Go to Top of Page

peter.cook

UK
356 Posts

Posted - 01/29/2004 :  6:13:08 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi CP,

Thanks for this (and others) reply. Am I missing something here? I've always used LT_set_var to pass values back to LabTalk variables. Is this not necessary as per your example then?

Cheers,

Pete

Go to Top of Page

cpyang

USA
1406 Posts

Posted - 01/29/2004 :  7:41:21 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
passing variables from OC back to LT was added in 70 SR4. LT_set_var etc was in the original support when OC was first started.

Ee have been adding support for passing various things between OC and LT such that LT can be extended via OC functions, to make LT more like MATLAB, so to speak.

CP


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