Print Page | Close Window

Arrays in reports

Printed From: MetaCase
Category:
Forum Name: MetaEdit+
Forum Description: All topics relating to MetaEdit+ or DSM
URL: https://www.metacase.com/forums/forum_posts.asp?TID=23
Printed Date: 27.Mar.2026 at 00:26
Software Version: Web Wiz Forums 12.05 - http://www.webwizforums.com


Topic: Arrays in reports
Posted By: nelly
Subject: Arrays in reports
Date 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



Replies:
Posted By: stevek
Date 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.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.05 - http://www.webwizforums.com
Copyright ©2001-2022 Web Wiz Ltd. - https://www.webwiz.net