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
 LabTalk Forum
 insert rows with a complex script

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
elnino 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?

6   L A T E S T    R E P L I E S    (Newest First)
VladGets1 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!

elnino 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?
elnino 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?
Hideo Fujii 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 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 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.

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