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
 Origin Forum
 Origin C -Calculations from max in specified range
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

cab0008

25 Posts

Posted - 02/11/2011 :  6:10:40 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
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

Penn

China
644 Posts

Posted - 02/12/2011 :  01:11:47 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page

cab0008

25 Posts

Posted - 02/12/2011 :  9:26:27 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you very much, your answer was perfect and this was a wonderful summary of many useful functions.
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