Jump to content

How to declare arrays if I don't know their number?


mike2003
 Share

Go to solution Solved by Nine,

Recommended Posts

Classic array creation method

Local $aArray[4]
$aArray[0] = "Jasper"
$aArray[1] = "Beethoven"
$aArray[2] = "Pinky"
$aArray[3] = "Fidget"

But what if I need several arrays from a file, and I don't know how many arrays there will be?

Local $aArray1[4]
Local $aArray2[10]
Local $aArray3[6]
Local $aArray4[2]
Local $aArray...[...]

How can I declare arrays at runtime? Maybe an array list whose length I can change?
Is there another way to store such data?

Link to comment
Share on other sites

  • Developers

Did you look at the Helpfile? https://www.autoitscript.com/autoit3/docs/intro/lang_variables.htm

Quote

Arrays and Maps

AutoIt has 2 types of data collection variables: Arrays and Maps.

Arrays are much faster for random access and can have multiple dimensions - a dimension size is fixed at the initially declared value (although it can be altered using ReDim).

 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Maps are only available in Beta version.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Version=Beta
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

Local $array[10] = [1,2,3,4,5,6,7,8,9,0]

Local $map[]

$map["SomeId"] = $array

ConsoleWrite($map.SomeId[3] & @CRLF)

 

Link to comment
Share on other sites

  • Solution

You could use the com object Scripting.Dictionnary which is very close to map :

#include <Constants.au3>
#include <Array.au3>

$sd = ObjCreate("Scripting.Dictionary")

Local $array[10] = [1,2,3,4,5,6,7,8,9,0]

$sd("SomeId") = $array
ConsoleWrite($sd("SomeId")[3] & @CRLF)

 

Link to comment
Share on other sites

Link to comment
Share on other sites

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...