![]() |
Arrays in reports |
Post Reply
|
| Author | |
nelly
Member
Joined: 10.Apr.2008 Points: 2 |
Post Options
Thanks(0)
Quote Reply
Topic: Arrays in reportsPosted: 10.Apr.2008 at 13:11 |
|
When writing a report, can I use arrays using MetaEdit+ 4.5? and what about MetaEdit+ 4.5 SR1? Cheers |
|
![]() |
|
stevek
MetaCase
Joined: 11.Mar.2008 Points: 643 |
Post Options
Thanks(0)
Quote Reply
Posted: 10.Apr.2008 at 14:16 |
|
Sure: there's no special syntax needed for arrays, or even associative arrays (where the "index" is a string not an integer). You just make the variable name include both the array and the index. E.g.
variable 'myArray_1' write 'first' close
variable 'myArray_2' write 'second' close
The structure of the variable names themselves is up to you: if you prefer $myArray[1] you can build it like that too. You can also use a shorter syntax for assignment, if you have 4.5 SR1 (everything here works in both 4.5 and 4.5 SR1, unless stated otherwise):
$myArray[1]='first'
Using the longer variable...write...close syntax lets you build up the variable name bit by bit, which is useful when you want the index to vary. The following will create $myArray_1 containing the name of the first object of type 'MyObjectType', $myArray_2 for the second:
$ix='1'
foreach .MyObjectType
{
variable
'myArray_' $ix++
write
id
close
}
Perhaps better for many cases is to use one long string variable, with each line being one element of the array. You can iterate over the elements of such variables easily in 4.5 SR1:
$myLines=''
foreach .MyObjectType
{
variable 'myLines' append
if $myLines then newline endif /* prevent an extra newline at the start */
id
close
}
/* Later, to iterate over the "array" (requires 4.5 SR1) */
do $myLines
{
id
}
For an associative variable, e.g. to be able to look up the type later:
foreach .MyObjectType
{
variable 'typeForId_'
id
write
type
close
}
/* Later, if we have a variable $thisId and want to output its type */
variable 'typeForId_' $thisId read
Having said all that, normally there's no need for variables. The information you need is generally to be found on the stack with id;1 etc. That's nicer too, because you don't need to do any work for it, and you have full access to the information of that object. Variables only store string versions of the information, so if you need the id, the :Foo property and the type, you'd need to create variables for all of them. From the stack, you can just pick them up as id;1 :Foo;1 type;1 etc. Edited by stevek - 10.Apr.2008 at 18:24 |
|
![]() |
|
Post Reply
|
|
| Tweet |
| Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |