Caution: Separate Command in version 7.2 050

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
User avatar
tony_smith
Pro Scripter
Posts: 70
Joined: Wed May 14, 2003 8:25 pm
Location: Vancouver BC Canada

Caution: Separate Command in version 7.2 050

Post by tony_smith » Fri Mar 26, 2004 4:10 pm

I upgraded to the latest version yesterday. The new version has a fix for the Separate command.People have been using work-arounds.

Overnight, I had a system crash because an old script, containing the Separate command looped infinitely. I have not had a chance to debug the macro yet (Still cleaning up data), however I thought I should post a heads-up on this in case anyone else was having a problem.

Here is the section of my code that I believe needs debugging...

Remark>Get File List Loop
GetFileList>TP,files
Separate>files,;,file_names
Let>k=0
Repeat>k
Let>k=k+1
FileSize>file_names_%k%,size
FileDate>file_names_%k%,date
WriteLn>LFILE,result,file_names_%k%
WriteLn>LFILE,Size: %size% Date: %date%
WriteLn>LFILE,
Until>k,file_names_count

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Fri Mar 26, 2004 10:09 pm

Hi,

I've been unable to duplicate this. Your code works fine and I have made other tests of a similar nature and no problems found. Anyone else?
MJT Net Support
[email protected]

User avatar
tony_smith
Pro Scripter
Posts: 70
Joined: Wed May 14, 2003 8:25 pm
Location: Vancouver BC Canada

Post by tony_smith » Fri Mar 26, 2004 11:02 pm

I have sent the code with debug screenshots... see Support Ticket 790814. I could not include the entire script and lookup file here as they contain privileged info.

Version 040 and version 050 give different array results using the same data.

User avatar
tony_smith
Pro Scripter
Posts: 70
Joined: Wed May 14, 2003 8:25 pm
Location: Vancouver BC Canada

The Answer is...

Post by tony_smith » Tue Mar 30, 2004 10:57 pm

Support sent me this reply... sometimes the answers are too obvious.

I see what the problem is. file_names_count used to incorrectly report 1 when there were in fact zero files in the list. The loop starts with k being equal to 1 and tries to loop until k = file_names_count. Therefore before the bug was fixed you used to get one iteration with an error on the filesize and filedate because there is no such file called file_names_1. Now that that file_names_count correctly reports 0 your loop will now try to iterate k from 1 to 0. Clearly it can iterate k from here until eternity but if it starts at 1 it will never reach 0 by adding 1 each time!

The elegant solution is to not do the loop if file_names_count is zero (only do it if there are files in the list). So you could do something like:

If>file_names_count>0,doloop,skiploop

Or in your case just jump back to loop1:

Separate>files,;,file_names
If>file_names_count=0,loop1
Let>k=0
Repeat>k
etc...

A dirtier fix if you want it to act like it used to and give you those filesize/filedate file not found errors is to loop until k = file_names_count+1 :

Let>fc=file_names_count+1
Repeat>k
...
...
Until>k,fc

You are a victim of an earlier bug letting you down gracefully (By allowing filesize/filedate to report on errors when no such file exists). I'm sure you'll appreciate that file_names_count *should* report zero when there are zero files in the list. And one should only loop through a list of files if there is indeed a list of files to loop through. One can't loop through an empty list.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts