Last array position

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
papi20ver
Newbie
Posts: 10
Joined: Fri Jan 11, 2008 3:52 pm

Last array position

Post by papi20ver » Thu Jan 17, 2008 10:22 pm

Greetings.
Please what´s the syntax to declare the last array position ?
Example:
Let>t=0
Repeat>t
Let>t=t+1
Let>filename=Tip_Nor[%t%]
Until>t=????

Some languages, as PERL, has an specific syntax ($#Tip_Nor) to declare the last index.
Thanks. Papi.
Papi

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Jan 17, 2008 10:38 pm

Until>t=????
???? will be an integer either as a number or a variable value that is a number. You will need to either explicitly place a number in the code, e.g. Until>t=10 Or you will need to programatically determine the number, assign it to a variable and use the variable with the until> function. For example:

GetFileList>c:\temp\*.*,files
Separate>files,;,file_names

Let>t=0
Repeat>t
Let>t=t+1
Let>filename=Tip_Nor[%t%]
Until>t=%file_names_count%


GetFileList> creates a list of files and Separate> assigns each list item to a variable and also creates variable_count that contains the number of items in the list.

Snickers
Macro Veteran
Posts: 151
Joined: Thu Dec 09, 2004 3:01 pm
Location: Somewhere in TX

Post by Snickers » Fri May 30, 2008 5:40 pm

Using this same principle, how would this work:

[code]
ReadFile>d:\jobs.txt,inFile
Separate>inFile,CRLF,lines
//
Let>j=0
Let>k=0
Let>combined=
Repeat>k
Let>j=j+1
Let>k=k+1
Let>this_line=lines_%k%

//this position code starts on the second line after my job number is found.
Position>#,this_line,1,p
//p will = 1 when the script reaches the next job number, which is the point I will stop storing variables and write what I have to excel.
If>p=1
//found line starting with #,

If>combined
//output variables to excel

Endif
//reset combined
Let>combined=
Else
Let>combined=1
Let>var_%j%=%this_line%
//OMIT THIS LINELet>combined=%combined%%this_line%
Endif

Until>k=lines_count
[/code]


how can i send all of the collected variables noted as var_%j% to excel. how can i identify all variables in this array? Sometimes there will be 3-20 lines of text.
how do i know how many items are in an array?

If there are 3 lines, var_1, var_2, and var_3 will have a value in there, but how can I know which var_# have been written.

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