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
 Origin Forum
 Origin C -Calculations from max in specified range

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
cab0008 Posted - 02/11/2011 : 6:10:40 PM
Hey everyone,

I know that this type of thing can be done easily with labtalk but for some reason labtalk is not calculating this properly and I think it may work and be more efficient in Origin C.
So, I was wondering if anyone had any simple and concise Origin C code for automating the following type of calculation:

[RESULTSSHEET]1!col(18)[L]$=D/G
RESULTSSHEET!wks.col18.name$ = D/G

range Drange=[DATASHEET]1!col(2)[1000:2000]
Dmax=max(Drange)

range Grange=[DATASHEET]1!col(2)[2000:3000]
Gmax=max(Grange)

range DandGrange=[DATASHEET]1!col(2)[1500:2500]
DandGmin=min(DandGrange)

[RESULTSSHEET]1!cell(1,18)=(Dmax-DandGmin)/(Gmax-DandGmin)



So, basically I'm wanting to know if you can convert this labtalk code into origin C code easily.

Thank you, any help is greatly appreciated.
Origin Ver. and Service Release (Select Help-->About Origin): 8.0 SR5
Operating System: Windows
2   L A T E S T    R E P L I E S    (Newest First)
cab0008 Posted - 02/12/2011 : 9:26:27 PM
Thank you very much, your answer was perfect and this was a wonderful summary of many useful functions.
Penn Posted - 02/12/2011 : 01:11:47 AM
Hi,

1. Get the Column from the Worksheet, and set long name and short name by using methods SetLongName and SetName respectively.

2. Get part of data from the column by using vector.

3. Calculate the maximum and minimum of the data by using max and min functions respectively.

4. Set the value to a cell of the worksheet by using SetCell method.

About your issue, you can refer to:

void test()
{
	string strWks;
	strWks = "[RESULTSSHEET]1";  // worksheet name
	Worksheet wks(strWks);
	if(!wks)
		return;
	
	Column col = wks.Columns(17);  // zero-based index
	if(!col)
		return;
	
	if(col.SetLongName("D/G"))  // set long name
		out_str("set long name successfully");
	
	if(col.SetName("DG"))  // cannot have "/" in short name
		out_str("set name successfully");
	
	string strWks1;
	strWks1 = "[DATASHEET]1";  // worksheet name
	Worksheet wks1(strWks1);
	if(!wks1)
		return;
	
	Column col1 = wks1.Columns(1);  // zero-based index
	if(!col1)
		return;
	vector Drange(col1, 999, 1999);  // zero-based index of row
	vector Grange(col1, 1999, 2999);
	vector DandGrange(col1, 1499, 2499);
	
	double Dmax, Gmax, DandGmin;
	Dmax = max(Drange);  // get maximum
	Gmax = max(Grange);  // get maximum
	DandGmin = min(DandGrange);  // get minimum
	
	if(wks.SetCell(0, 17, (Dmax-DandGmin)/(Gmax-DandGmin)))  // set the value to a cell of worksheet
		out_str("set cell successfully");	
}


Penn

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