Setting array dimensions with parameters
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā2021-07-12
09:00 AM
- last edited on
ā2021-09-14
09:01 AM
by
Noemi Balogh
I'm trying to set an array's dimension by using a parameter value, like this:
num = 3 !will be set by the parameter DIM myArray[num]This gives an error as:
It does work, of course, with: DIM myArray[3] , but I want this array-dimension to be based on a parameter.
How to achieve this?
Thanks.
- Labels:
-
Library (GDL)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā2021-07-12 10:39 AM
num=3 DIM myArray[] FOR i=1 to num myArray=something NEXT i

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā2021-07-12 11:28 AM
num = 3 dim _myArray[] for i = 1 to num if i > vardim1(myArray) then _myArray = "put a default value here" else _myArray = myArray endif next i myArray = _myArray parameters myArray = myArray

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā2021-07-12 12:09 PM
Kristian wrote:It depends on what you need your array. I'm using the method you describe when I have an array (let say coordinates of polygon) and I want to add a new node. Then if I have an array with three points coordinates, I'm passing their coordinates to temporary array, adding at the end additional dimension and coordinates of the new point.
best practice is to build a local array and pass it to to the parameter array, and then also use/reference this local array (assuming master script) in other scripts instead of the parameter array as this means you don't have to wait for the parameter to update in the array for it to apply in the code because the local array already has the value from the master script which is run first.
num = 3 dim _myArray[] for i = 1 to num if i > vardim1(myArray) then _myArray = "put a default value here" else _myArray = myArray endif next i myArray = _myArray parameters myArray = myArray
I also can say - I've found many GDL scripts (especially from ArchiCAD library) are very very big. They writing with 20-30 lines that potentially possible to write with 10. I don't know where is the secret in it - is it example of good programming Graphisoft is showing to us (well they are mathematicians, studied programming in university) - but somehow I have decided to develop different style trying to make scripts as short as possible. And also that script possible to read by human - without additional notes and explanations, so I'm paying extra attention to variable names.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā2021-07-12 12:16 PM
Podolsky wrote:I agree completely. You should be as efficient as possible in your code. Most of my arrays require the dynamic variation so that is the method I apply. If your application does not need to be dynamic like editing a polygon then perhaps it is overkill.
It depends on what you need your array. I'm using the method you describe when I have an array (let say coordinates of polygon) and I want to add a new node
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā2021-07-12 12:22 PM
Podolsky, yes, that looks like a way around it.
How do you initialise a two-dimensional array as a blank? DIM myArray[][] ?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā2021-07-12 12:39 PM
dushyant wrote:yes
Thanks, Podolsky & Kristian.
Podolsky, yes, that looks like a way around it.
How do you initialise a two-dimensional array as a blank? DIM myArray[][] ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā2021-07-12 04:09 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā2021-07-13 10:32 AM