Arrays?

Scripts and programs to automate Astroart
Post Reply
Forum_2015
Posts: 353
Joined: 07 Dec 2018, 15:04

Arrays?

Post by Forum_2015 »

I could not find any documentation regarding arrays (either numeric or string). Do they exist?

Forum_2015
Posts: 353
Joined: 07 Dec 2018, 15:04

Re: Arrays?

Post by Forum_2015 »

For character arrays, you may use strings:

Code: Select all

filters = "LRRGGBB"
For i = 1 to Len(filters)
  Print filters[i]
Next i
for string arrays, you may use the { } syntax, see the example:
Menu / Demos / Basic 4

for generic arrays, the standard Dim keyword is supported, but this feature is currently experimental (5.42 or newer). It works well, but there are two limitations: all arrays are global, whole arrays cannot be passed as function parameters.
Some examples:

Code: Select all

Dim arr(10)
For i = 1 to 10 
  arr(i) = i*i
Next i
For i = 1 to 10 
  Print arr(i)
Next i
arrays will be actually released as "lists", the following example is quite nice:

Code: Select all

Dim arr = {4, 5*5, "hel"+"lo", 0.5, Sqr(64)}
For i = 0 to 4 
  Print arr(i)
Next i

User avatar
Rudi
Posts: 160
Joined: 08 Jan 2019, 04:47

Re: Arrays?

Post by Rudi » 15 Aug 2022, 05:17

Forum_2015 wrote:
07 Dec 2018, 22:07
For character arrays, you may use strings:

Code: Select all

filters = "LRRGGBB"
For i = 1 to Len(filters)
  Print filters[i]
Next i
for string arrays, you may use the { } syntax, see the example:
Menu / Demos / Basic 4

for generic arrays, the standard Dim keyword is supported, but this feature is currently experimental (5.42 or newer). It works well, but there are two limitations: all arrays are global, whole arrays cannot be passed as function parameters.
Some examples:

Code: Select all

Dim arr(10)
For i = 1 to 10 
  arr(i) = i*i
Next i
For i = 1 to 10 
  Print arr(i)
Next i
arrays will be actually released as "lists", the following example is quite nice:

Code: Select all

Dim arr = {4, 5*5, "hel"+"lo", 0.5, Sqr(64)}
For i = 0 to 4 
  Print arr(i)
Next i
How do one get the dimension of an array? Don't want to hardcode size in the script I am creating.

Code: Select all

Dim arr = {4, 5*5, "hel"+"lo", 0.5, Sqr(64)}
For i = 0 to arr.Dim()     <==== error, also tried "Dim", "Len()", "Len", .... and many more options 
  Print arr(i)
Next i
[/quote]
/Rudi

fabdev
Posts: 503
Joined: 03 Dec 2018, 21:43

Re: Arrays?

Post by fabdev » 16 Aug 2022, 16:47

Hello,
the function to get the length of an array is: UBound(array)
For more information see the paragraph "Types and variables"
Fabio.

User avatar
Rudi
Posts: 160
Joined: 08 Jan 2019, 04:47

Re: Arrays?

Post by Rudi » 17 Aug 2022, 07:26

Thanks - that worked out fine.
/Rudi

Post Reply