Author |
Topic |
|
elnino
20 Posts |
Posted - 10/18/2016 : 12:12:41 PM
|
Hello everyone!
I hope I am in the right Forum.
I want to insert rows in my worksheet if a comparison with three columns are not fit. And then there should be insert a row in everx column except the three columns for comparison.
Small scripts as wks.insertRows(2;1;4) or wks.insertRows (2) works but not the complex scripts as:
example:
int hour, day, month, year; int hourIndex = 4; int dayIndex = 5; int monthIndex = 6; int yearIndex = 7; int expectedDay, expectedMonth, expectedYear; int expectedHour = 0; int c1 = 1; int c2 = 2; int c3 = 3; int rowIndexForCompareDate = 1; int i = 0; while (i < wks.nRows) { i++; hour = wcol(hourIndex)[i]; day = wcol(dayIndex)[i]; month = wcol(monthIndex)[i]; year = wcol(yearIndex)[i]; expectedDay = wcol(c1)[rowIndexForCompareDate]; expectedMonth = wcol(c2)[rowIndexForCompareDate]; expectedYear = wcol(c3)[rowIndexForCompareDate]; if (day != expectedDay || month != expectedMonth || year != expectedYear || hour != expectedHour) { wks.insertRows(i;1;4); wcol(hourIndex)[i] = expectedHour; wcol(dayIndex)[i] = expectedDay; wcol(monthIndex)[i] = expectedMonth; wcol(yearIndex)[i] = expectedYear; } if (expectedHour == 23) { rowIndexForCompareDate++; expectedHour = 0; } else expectedHour++; }
example 2:
int hour; int day; int month; int year; int hourIndex = 4; int dayIndex = 5; int monthIndex = 6; int yearIndex = 7; int expectedDay; int expectedMonth; int expectedYear; int expectedHour = 0; int c1 = 1; int c2 = 2; int c3 = 3; int rowIndexForCompareDate = 1; int i = 0; while (i < wks.nRows) { i++; hour = wcol(hourIndex)[i]; day = wcol(dayIndex)[i]; month = wcol(monthIndex)[i]; year = wcol(yearIndex)[i]; expectedDay = wcol(c1)[rowIndexForCompareDate]; expectedMonth = wcol(c2)[rowIndexForCompareDate]; expectedYear = wcol(c3)[rowIndexForCompareDate]; if (day != expectedDay || month != expectedMonth || year != expectedYear || hour != expectedHour) { wks.insertRows(i;1;4); wcol(hourIndex)[i] = expectedHour; wcol(dayIndex)[i] = expectedDay; wcol(monthIndex)[i] = expectedMonth; wcol(yearIndex)[i] = expectedYear; } if (expectedHour == 23) { rowIndexForCompareDate++; expectedHour = 0; } else { expectedHour++;}
Does somebody can help me?
|
|
Hideo Fujii
USA
1582 Posts |
Posted - 10/18/2016 : 1:45:13 PM
|
Hi elnino,
I can at least see a while{...} loop in your code, but LabTalk doesn't have this command. There might be other issues, and if so, you can post pretty-printed code with indentation so that reader can easily hep you.
Hope this helps.
--Hideo Fujii OriginLab
P.S. Please avoid double-posting because some people waste time to read the same post twice. You can just submit to the LabTalk forum if it contains the script-related issue. |
Edited by - Hideo Fujii on 10/18/2016 1:58:09 PM |
|
|
elnino
20 Posts |
Posted - 10/18/2016 : 4:17:59 PM
|
Hi Hideo Fujii,
thank you very much for both advice!
I tried it and i came a step further.
Now, the next step doesnt work:
for (ii=1; ii <= wks.nRows; ii++) { if (col(4)[ii] == 1) { wks.insertRows(ii); } }
Where is the mistake? Should I use wcol instead of col? I tried it, but it also didnt work.
I hope somebody can help me! |
|
|
Hideo Fujii
USA
1582 Posts |
Posted - 10/18/2016 : 4:52:12 PM
|
Hi elnino,
Assume col(4)[1] is 1, the code inserts an empty row at the first row. Now ii comes to 2, and the original first row is there, and again an empty row is inserted at row 2, ... and go on. The problem is to add/remove rows, but you are using the same index, ii simulteneously. I think it's a risky operation. I think you consider to output a new worksheet by using two indexes for both source and destination.
Hope this helps.
--Hideo Fujii OriginLab |
|
|
elnino
20 Posts |
Posted - 10/19/2016 : 09:13:49 AM
|
Hi Hideo Fujii,
thank you again for your help!
What do I have exactly to write if I want to use another worksheet?
For example as you descriped? |
|
|
elnino
20 Posts |
Posted - 10/19/2016 : 09:22:37 AM
|
Ok, I try to specify what I want to write: I need to write results (These are in this case whol rows, sometimes copied rows from the first worksheet) in the second worksheet. How do I have to write it exactly as script? |
|
|
VladGets1
Germany
12 Posts |
Posted - 11/02/2016 : 05:05:42 AM
|
Thank you for this information!)))
quote: Originally posted by elnino
Hi Hideo Fujii,
thank you very much for both advice!
I tried it and i came a step further.
Now, the next step doesnt work:
for (ii=1; ii <= wks.nRows; ii++) { if (col(4)[ii] == 1) { wks.insertRows(ii); } }
Where is the mistake? Should I use wcol instead of col? I tried it, but it also didnt work.
I hope somebody can help me!
|
|
|
|
Topic |
|