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
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum
 Origin Forum
 issue in simple for loop
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

mwambach

6 Posts

Posted - 08/23/2016 :  1:12:52 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hi there!

I wrote a simple script in Labtalk to delete rows with no value in Col(C). Unfortunately when I run it in the script window, only every other empty row is deleted. What's the error in the script? Cheers!

a=1;
for (i=1;i<=1000;i++)
{
if (Col(C)[a]==0/0)
{
wks.deleteRows(a);
}
a=a++;
}

snowli

USA
1379 Posts

Posted - 08/23/2016 :  2:37:36 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hello, this is because after you run wks.deleteRows(a) once, the row is already shifted upwards so the row indexing is updated.

E.g. if there are some missing values in row 10, 11, 12, 13.
after deleting row 10, the old row 11, 12, 13 are row 10, 11, 12 now.

So instead of looping from 1 on, try loop of end of rows.

for (i=wks.nrows;i>=1;i--)
{
if (Col(C)[i]==0/0)
{
wks.deleteRows(i);
}
}


Thanks, Snow
Go to Top of Page

mwambach

6 Posts

Posted - 08/23/2016 :  2:51:44 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Snow!

Thanks for your help!
Go to Top of Page

snowli

USA
1379 Posts

Posted - 08/23/2016 :  4:09:51 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
You are welcome.

Thanks, Snow
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000