MetaCase Homepage
Forum Home Forum Home > > MetaEdit+
  New Posts New Posts RSS Feed - Arrays in reports
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Arrays in reports

 Post Reply Post Reply
Author
Message
nelly View Drop Down
Member
Member
Avatar

Joined: 10.Apr.2008
Points: 2
Post Options Post Options   Thanks (0) Thanks(0)   Quote nelly Quote  Post ReplyReply Direct Link To This Post Topic: Arrays in reports
    Posted: 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
Back to Top
stevek View Drop Down
MetaCase
MetaCase
Avatar

Joined: 11.Mar.2008
Points: 643
Post Options Post Options   Thanks (0) Thanks(0)   Quote stevek Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.05
Copyright ©2001-2022 Web Wiz Ltd.

This page was generated in 0.031 seconds.