Author |
Topic  |
|
tonyv
Germany
Posts |
Posted - 09/27/2006 : 04:51:53 AM
|
Hi, I wrote the following short program: void rixs (int m) //m-number of rows { string name;int i=1;int l=0;
Worksheet wks = Project.ActiveLayer(); if(!wks) return; string strDataE1 = wks.Columns(2).GetDatasetName(); Dataset E1(strDataE1); string strDataE2 = wks.Columns(0).GetDatasetName(); Dataset E2(strDataE2); string strDataE3 = wks.Columns(3).GetDatasetName(); Dataset E3(strDataE3); E1.SetSize(m); E2.SetSize(m); E3.SetSize(m);
wks.Create("Origin.otw", CREATE_VISIBLE_SAME); wks.AddCol(); wks.AddCol(); Dataset dd1(wks.Columns(0).GetDatasetName()); Dataset dd2(wks.Columns(1).GetDatasetName()); dd1.SetSize(m); dd2.SetSize(m);
for (int j=0; j<m; j++) { if (E1[j]==i) { Worksheet wks = Project.ActiveLayer(); dd1[l]=E2[j]; dd2[l]=E3[j]; l=l+1; }else {i=i+1;
wks.Create("Origin.otw", CREATE_VISIBLE_SAME); wks.AddCol(); wks.AddCol(); Dataset dd1(wks.Columns(0).GetDatasetName()); Dataset dd2(wks.Columns(1).GetDatasetName()); dd1.SetSize(m); dd2.SetSize(m); l=0; } } }
it does, what I need except that when I enter the "else" and create new Worksheet, I call the two needed columns again with dd1 and dd2, but when I enter "if" again dd1 and dd2 are associated with the old Worksheet. I understand why, it is so, but I can not come up with an idea how to fix it. Thanks for any suggestion.
Tony
|
|
Mike Buess
USA
3037 Posts |
Posted - 09/27/2006 : 08:39:57 AM
|
Hi Tony,
You declare or create the same Worksheet and Dataset names more than once which makes your code hard to follow. Also, it appears that datasets are used in the else statement only to set the number of rows in wks. wks.SetSize(numRows,numCols) is faster and also takes the place of your double wks.AddCols(). I'm not sure the following code does exactly what you want but it's a start.void rixs (int m) //m-number of rows { int i=1; int l=0; Worksheet wks1 = Project.ActiveLayer(); if( !wks1 ) return; wks1.SetSize(m,wks1.GetNumCols()); Dataset E1(wks1,2); Dataset E2(wks1,0); Dataset E3(wks1,3);
Worksheet wks2; wks2.Create("Origin.otw", CREATE_VISIBLE_SAME); wks2.SetSize(m,4); Dataset dd1(wks2,0); Dataset dd2(wks2,1);
for (int j=0; j<m; j++) { if( E1[j]==i ) { dd1[l] = E2[j]; dd2[l] = E3[j]; l++; } else { i++; Worksheet wks; wks.Create("Origin.otw", CREATE_VISIBLE_SAME); wks.SetSize(m,4); l = 0; } } }
Mike Buess Origin WebRing Member |
 |
|
tonyv
Germany
Posts |
Posted - 09/27/2006 : 09:39:42 AM
|
Hi Mike,
Thank you for the answer and for the corrections. It is obvious that my program skills are not excellent :). Your version does the same mistake. The task is like this:
1.I have a very long worksheet with four columns. 2.The first and fourth columns should be cut on pieces and each piece should be entered in a new Worksheet with two columns. 3. The number of pieces is in the third column, which contains repeating numbers until the new piece comes. An example:
1 4 1 3 2 4 1 8 3 4 1 45 1 4 2 212 2 4 2 45 3 4 2 8 1 4 3 234 2 4 3 2432 3 4 3 8
My program creates three worksheets but rewrites always the numbers in the first worksheet.
Thank you again... Tony
|
 |
|
Mike Buess
USA
3037 Posts |
Posted - 09/27/2006 : 11:32:56 AM
|
Hi Tony,
Now I see what you want to do and yes, dd1 and dd2 are always attached to the worksheet that was created first. You don't really need datasets for this task because you can get and set the columns one cell at a time. Note that wks.SetCell() resizes the column if necessary so there is no need to adjust the sizes of the new worksheets...void rixs (int m) //m-number of rows { int i = 0; int l = 0; Worksheet wks1 = Project.ActiveLayer(); if( !wks1 ) return; wks1.SetSize(m,-1); Worksheet wks2; for (int j=0; j<m; j++) { if( wks1.Cell(j,2)!=i ) { wks2.Create("Origin.otw", CREATE_VISIBLE_SAME); i++; l = 0; } wks2.SetCell(l,0,wks1.Cell(j,0)); wks2.SetCell(l,1,wks1.Cell(j,3)); l++; } }
Mike Buess Origin WebRing Member
Edited by - Mike Buess on 09/27/2006 11:37:12 AM |
 |
|
tonyv
Germany
Posts |
Posted - 09/27/2006 : 11:40:27 AM
|
Hi Mike,
This mistake appeared:
D:\Program Files\OriginLab\Origin7\OriginC\rixs_3.c(32) :Error, Member function Worksheet::SetSize not defined or does not have matching prototype.
My Origin version is:7.0552 (B552)
Tony
|
 |
|
Mike Buess
USA
3037 Posts |
Posted - 09/27/2006 : 11:50:14 AM
|
Sorry, above code was written in Origin 7.5. wks1.SetSize(m,-1) is not really necessary so you can delete it.
Mike Buess Origin WebRing Member |
 |
|
tonyv
Germany
Posts |
Posted - 09/27/2006 : 11:56:24 AM
|
Great, it works!
I am charmed as usual :)!
Tony
|
 |
|
|
Topic  |
|
|
|