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
 3 questions reagrding Column access
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Physikant

2 Posts

Posted - 06/14/2014 :  07:09:24 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hi!
Im using Origin 9 SR2.
I'm programming origin C and I really do not want to use the other origin programming languages.
So here are my questions:
1) Is there a way to get the index of the last number in a row? With several functions like importing, rows after the last number are filled with "--". I want to avoid these and just get the index of the last real number. So I tried GetSize(), GetUpperBound(),NumRows(), but nothing yields this. Is there a way?
2) The user of my script has used the masking tool to mask some data in a plot. I now want to calculate something from the column with the masked values, but the masked values are ignored. Is there a possibility to acess data in a column while ignoring masking? Or if this is more simple: is it possible to remove the masking from a column?
3) Is there a possibility to change what is written in the "set column values" menu, rather than calculating the values of a column by software and then just inserting it there? It would be nice if my user could alter the formula for the calculation afterwards ...
Thanks in advance!
Nikolas

EDIT: third question added.

Edited by - Physikant on 06/14/2014 08:00:45 AM

greg

USA
1378 Posts

Posted - 06/16/2014 :  2:09:55 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Here is an example that removes all masked values from a column and also returns the last value in the column.

double sample1(string strWks, uint iCol)
{
Worksheet wks(strWks);
Dataset ds(wks, iCol); // iCol indexed from 0
uint iSize = ds.GetSize();

// Remove mask from column range
DataRange dr;
dr.Add(wks,iCol,"junk");
dr.SetMask(0); // 1 would set as masked

// Get the last value
return ds[iSize - 1];
}

Your user can select the column with the formula and press Ctrl+Q to open the Set Values dialog and change the formula. 9.1 users have the option of showing the F(x)= header row and you can edit the formula right there.
Go to Top of Page

Physikant

2 Posts

Posted - 06/17/2014 :  04:16:30 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hey greg,

thank you very much!
What I meant with my last question is: can I give the formula of a row via Origin C? Is there a possibility to change via OriginC, what the user can edit by pressing ctrl+Q?
Right now, I calculate values and just insert them in the column, after that, the formula is lost, if the user opens the Set Values dialog, it's empty.
Is there a way to write there via Origin C?
Best regards,
Nikolas
Go to Top of Page

Castiel

343 Posts

Posted - 06/17/2014 :  12:04:10 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by Physikant

Hey greg,

thank you very much!
What I meant with my last question is: can I give the formula of a row via Origin C? Is there a possibility to change via OriginC, what the user can edit by pressing ctrl+Q?
Right now, I calculate values and just insert them in the column, after that, the formula is lost, if the user opens the Set Values dialog, it's empty.
Is there a way to write there via Origin C?
Best regards,
Nikolas



DataObject::GetFormula()
and
DataObject::SetFormula()


妾+   午旦  妹罕妾  妾伊    用仇  妾/     岫ㄞ
 妾京用 仍巨  件 侈   件戶' 甘岫平   /欠  白岫妹
   併             艮          岫  奈 白   岫
                              岫
Go to Top of Page

greg

USA
1378 Posts

Posted - 06/17/2014 :  12:15:25 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
We have a csetvalue X-Function which lets you programmaticaly do what Set Values does.
Here is an example:

#include <XFbase.h>

int sample_set_values(string strWks, int iCol, string strFormula, string strScript)
{
// Create an 'XF' object
XFBase xfSCV("csetvalue");
if( !xfSCV.IsValid() )
{
out_str("Failed to load csetvalue X-Function.\n");
return -1;
}
Worksheet wks(strWks);
if( !wks.IsValid() )
{
out_str("Failed to attache to worksheet\n");
return -7;
}
Range ra;
ra.Add("Range1", wks, 0, iCol, -1, iCol); // A whole col (column C)
// csetvalue has four arguments which need to be set
if( !xfSCV.SetArg("col",ra) )
{
out_str("Failed to set range.\n");
return -2;
}
if( !xfSCV.SetArg("formula", strFormula) )
{
out_str("Failed to set formula.\n");
return -3;
}
if( !xfSCV.SetArg("script", strScript) )
{
out_str("Failed to set script.\n");
return -4;
}
if( !xfSCV.SetArg("recalculate", 0) )
{
out_str("Failed to set recalculate.\n");
return -5;
}
if( !xfSCV.Evaluate() )
{
out_str("Failed to evaluate the setvalue X-Function.\n");
return -6;
}
return 0;
}

Note that even though the XF called from LabTalk interprets columns indexed from 1, in the C environment column indexing is from 0. Also, called this way, recalculate is disregarded, but your user will be able to open Set Column Values and see/change what you put there.

e.g.
val = sample_set_values("[Book1]Sheet1",0,"100 * ds","dataset ds;ds = data(1,00);");
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