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 for Programming
 Forum for Origin C
 dynamic name

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
akerstan Posted - 06/05/2009 : 07:30:49 AM
Hallo,

I want to plot data from different worksheets, that is why I wrote a loop over all worksheets. This is working quite good.
Now in each loop a curve is created.

I would like to generate each curve with a different name. Therefor I did this:
(is there no other way to convert an integer to a string, than doing this by vectors???)

vector <int> vecn;

vector <string> veccount;


foreach (Folder sf in fldRoot.Subfolders) //loop over the subfolders of root folder
{

foreach (PageBase pg in sf.Pages) //loop over the pages in the subfolder
{
if (pg.GetType() == EXIST_WKS) //check if the page is an worksheet page
{

WorksheetPage wp(pg);
Worksheet wks(wp.Layers(0));
//


vecn=vecn+1;
//
convert_int_vector_to_string_vector( vecn, veccount);

// there must be an easier way to do this I know


string curvename= "crv"+veccount[0];

Curve "curvename";


I hope this is possible in some way.

bye,

Ann
1   L A T E S T    R E P L I E S    (Newest First)
Sophy Posted - 06/08/2009 : 02:56:13 AM
Hi, akerstan:

I'd like to point out some coding problem in you code before solving your problem.

You might have misused the vector<int> vecn, the problem is that vecn = vecn + 1, means that every item in vector vecn will increase by 1, e.g. {1, 2, 3} will become {2, 3, 4}.

If you want to convert a integer to a string, just assign the integer to a string variable, then Origin C can convert it automatically. I hope the following code will help you on understanding how it works.


#include <Origin.h>
#define	STR_CRV_NAME_PREFIX	"crv"
void dynamic_name_ex()
{
	vector<string>	vsCurveNames(0); //declare a string vector to store all curve names and reset it.
	int				nNumCrv = 0; //number of curves
	
	//get root folder
	Folder rootFdr = Project.RootFolder;
	
	foreach(Folder SubFdr in rootFdr.Subfolders)
	{
		foreach(PageBase pb in SubFdr.Pages)
		{
			if ( pb.GetType() == EXIST_WKS )
			{
				WorksheetPage wksPage(pb);
				foreach(Layer wkslyr in wksPage.Layers)
				{
					Worksheet wks(wkslyr);
					//do something
					//...
					
					//add new curve name
					nNumCrv++;
					string strCrvName = STR_CRV_NAME_PREFIX + nNumCrv; //Origin C will convert nNumCrv to string automatically, say 2 to "2", and catenate two strings and assign to strCrvName
					vsCurveNames.Add(strCrvName); //add to string vector;
				}
			}
		}
	}
}


BTW, you might have interest in how to plot all xyranges in current project on one graph, please refer to http://ocwiki.originlab.com/index.php?title=OriginC:Plot_all_worksheets_in_one_graph_layer

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