T O P I C R E V I E W |
Physikant |
Posted - 06/14/2014 : 07:09:24 AM 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. |
4 L A T E S T R E P L I E S (Newest First) |
greg |
Posted - 06/17/2014 : 12:15:25 PM 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);");
|
Castiel |
Posted - 06/17/2014 : 12:04:10 PM 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()
©c¡Ï ¤È¥¹ ©f¨u©c ©c¥ì ¥Î¤³ ©c/ ©¦£¯
©c¨Ê¥Î ¤´¥¨ ¥ó ¨× ¥ó¤á' ¥Ì©¦¥ /¤í ¥Õ©¦©f
¨Ö ¦á ©¦£þ ©` ¥Õ ©¦
©¦ |
Physikant |
Posted - 06/17/2014 : 04:16:30 AM 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 |
greg |
Posted - 06/16/2014 : 2:09:55 PM 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.
|
|
|