Sign in to follow this  
Followers 0
Guest Ultima

how to declare array with pre-initialized values?

5 posts in this topic

I want to declare an array with some pre-initialized values like

int Array[3] = {1, 2, 3}

Is there anyway to do it in AutoIt?

Share this post


Link to post
Share on other sites

Nope.

Only thing you can do is something like with StringSplit...

$array = StringSplit('Value 1,Value 2,Value 3', ',')

Or something similar.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

The correct syntax in AutoIt:

Method 1.

Dim $Array[3]
$Array[0] = 1
$Array[1] = 2
$Array[2] = 3

Method 2.

Dim $Array[3]
For $i = 0 To 2
   $Array[$i] = $i + 1
Next

Edit:

Or as Saunders mentioned.

Method 3.

$Array = StringSplit("1,2,3", ",")
Edited by SlimShady

Share this post


Link to post
Share on other sites

Thanks, I like the StringSplit method.

Share this post


Link to post
Share on other sites

Or use the included Array.au3 file function _ArrayCreate:

#include "Array.au3"

Dim $Array = _ArrayCreate(1, 2, 3)

My Projects:DebugIt - Debug your AutoIt scripts with DebugIt!

Share this post


Link to post
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
Sign in to follow this  
Followers 0