Could anyone give quick lesson on arrays? (length of array)
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2014-08-13 01:45 AM
‎2014-08-13
01:45 AM
Simple concept: I need to CALL an object a few times at user-defined spaces given in 1-dimensional array.
User manually inserts N amount of fields in an array in Object Parameters, like:
1'-0"
2'-8"
13'-6"
...and so forth
I'd like to use a FOR loop that inserts the CALLed object N times at specific intervals. Is this the correct approach? Thank you!
7 REPLIES 7
Anonymous
Not applicable
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2014-08-13 10:45 AM
‎2014-08-13
10:45 AM
Tip:
nSpaces=0 !conts add commands
for kont=1 to N do
add arrayName[kont], 0.000, 0.000
call callName
nSpaces=nSpaces+1
next kont
del nSpaces
nSpaces=0 !conts add commands
for kont=1 to N do
add arrayName[kont], 0.000, 0.000
call callName
nSpaces=nSpaces+1
next kont
del nSpaces
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2014-08-13 05:11 PM
‎2014-08-13
05:11 PM
Ilder,
Thank you,
if I'm understanding your response correctly, the basic loop example you shared with me assumes that N is a pre-defined number.
That's not the case -- I would like N to be automatically generated based on number of rows in the array when the array is parsed. How do I make the GDL engine return that number?
1) Parse the array
2) Calculate N of array elements in a column
3) for i=1 to N space objects at defined values
Next time the user adds or deletes a row, N is re-calculated. I'm sure it's simple, I'm just missing that bit.
Thank you,
if I'm understanding your response correctly, the basic loop example you shared with me assumes that N is a pre-defined number.
That's not the case -- I would like N to be automatically generated based on number of rows in the array when the array is parsed. How do I make the GDL engine return that number?
1) Parse the array
2) Calculate N of array elements in a column
3) for i=1 to N space objects at defined values
Next time the user adds or deletes a row, N is re-calculated. I'm sure it's simple, I'm just missing that bit.
Anonymous
Not applicable
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2014-08-13 07:22 PM
‎2014-08-13
07:22 PM
Hello,
You can declare dynamic arrays just using
For example
You can declare dynamic arrays just using
dim xxx[]or
dim yyy[][]The variables vardim1() and vardim2() return the array length
For example
rows= vardim1(xxx)or
columns= vardim2(xxx)Hope this helps.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2014-08-13 08:09 PM
‎2014-08-13
08:09 PM
Thank you, Juha.
I eventually reached the part of GDL manual where they explain how to build arrays. Let me explain myself a bit more:
See the attached screenshot with an array called myarray[4]
My question is: I don't want to hard code the number in brackets. It can be [4] or [1] or [52] but I do not know how to pass it to my FOR loop without hard coding it, because I'd like my users to add or delete as many rows as they want.
Is this possible at all...?
I eventually reached the part of GDL manual where they explain how to build arrays. Let me explain myself a bit more:
See the attached screenshot with an array called myarray[4]
My question is: I don't want to hard code the number in brackets. It can be [4] or [1] or [52] but I do not know how to pass it to my FOR loop without hard coding it, because I'd like my users to add or delete as many rows as they want.
Is this possible at all...?
Anonymous
Not applicable
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2014-08-13 08:45 PM
‎2014-08-13
08:45 PM
Hello,
Do not know if this is the case - just one
example getting values from one array to
another
Do not know if this is the case - just one
example getting values from one array to
another
!--value or master script dim xxx[] n= 0 for i = 1 to vardim1(myarray) if myarray > 0 then !--filter what is included to the array 'xxx' n= n+1 xxx= myarray endif next i !--make it a value list values 'mylist' xxx
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2014-08-13 09:34 PM
‎2014-08-13
09:34 PM
Juha wrote:
for i = 1 to vardim1(myarray)
GDL wrote:Awesome - *this* is exactly what I was looking for. I saw vardim1 in the manual, but didn't really know how it applied to my problem.
These functions return as integers the actual dimension values for the (array) expression specified as a parameter. They must be used if you want to handle correctly all actual elements of a dynamic array or an array parameter.
THANK YOU very much, Juha!

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2014-08-13 10:59 PM
‎2014-08-13
10:59 PM
There is a very good discussion of array sizing with examples here too.
Erich
AC 19 6006 & AC 20
Mac OS 10.11.5
15" Retina MacBook Pro 2.6
27" iMac Retina 5K
AC 19 6006 & AC 20
Mac OS 10.11.5
15" Retina MacBook Pro 2.6
27" iMac Retina 5K