A faster way to Separate

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Sat Mar 29, 2008 10:47 am

Referring to Me_again's code above:
Repeat>K
Let>APTData=Apt_%k%
Let>k=k+1
Until>K>APT-Count

What's the purpose of Let>APTData=Apt_%k%?
In fact, prior executing the line, APTdata has already been assigned with the content of c:\ftps\book1.txt.
I don't see how it could create an array.
Please enlighten me.
Thanks.

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Sat Mar 29, 2008 11:40 am

armsys wrote:Referring to Me_again's code above:
Repeat>K
Let>APTData=Apt_%k%
Let>k=k+1
Until>K>APT-Count

What's the purpose of Let>APTData=Apt_%k%?
In fact, prior executing the line, APTdata has already been assigned with the content of c:\ftps\book1.txt.
I don't see how it could create an array.
Please enlighten me.
Thanks.
The content of the file is split into an array of lines. The line prior to the Repeat/Until loop is a Separate line:

Separate>APTData,CRLF,APT

This splits the file data line by line into APT_1, APT_2 ... APT_n - one for each line.

The "Let>APTData=APT_%k%" line you refer to, inside the Repeat/Until accesses each array entry.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Sat Mar 29, 2008 12:06 pm

Hi mtettmar,
Thanks for your explanation. But the following loop haunts my curiosity. It keeps assigning the values of APT_1, APT_2 ... APT_n to the APTData.
APTData isn't an array, is it? The whole repeat loop doesn't make any sense. What's the meaningful purpose the repeat loop attempts to achieve?

Repeat>k
Let>APTData=APT_%k%
Let>k=k+1
Until>k>APT_Count

BTW, k wasn't initiated before the Repeat>K statement. Is it true that all uninitated/undeclared variables are assigned 0 (zero) by default?

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Sat Mar 29, 2008 12:58 pm

Perhaps APTData was a confusing choice of variable, although it doesn't really matter since the script no longer needs the entire file contents in the original APTData variable, since it is now in the array. So in fact it wouldn't be a problem using the same name for this variable.

Correct - you *DO* need to initialise the loop counter, otherwise the Let>k=k+1 will create a string, not add a number, because k is not defined.

However, MeAgain only posted a partial screen shot of his code. He may have initialised k earlier in the code than is visible.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Sat Mar 29, 2008 3:24 pm

Hi mtettmar,
Thanks for your quick answer. Now your explan makes a lot of sense.
I ran the Me_Again's sample code with MS debugger. APTData turns out be just a plain string variable, not an array, as shown in the Watch List.

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Sat Mar 29, 2008 3:29 pm

Yes, as I explained (perhaps I did a bad job), APTData first it contains the entire file contents. Separate is used to take the data in APTData and return an array called APT (APT_1, APT_2 etc). APTData is then also used to store each array value as the loop iterates. Don't think anyone has ever said that APTData is an array.

The array is created by the Separate command. It takes the file contents (in APTData and splits it out based on CRLF as the delimiter. So it splits the file by lines. So you end up with APT_1, APT_2 ... APT_n containing each line of the file.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

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