Jump to content

Array Stuff


Recommended Posts

Hey Guys...

I have been using AutoIt for 1 week now. It's a great tool but I couldn't manage Arrays.

I am trying to allocate to an array (which it's length will be randomly determined) a Random number and after that to read it or display it on a MsgBox.

Here is what I have done so far... :whistle:

$arrayLength=(1,20); will determine the array dimention
For $loop=1 to $arrayLength
   $myRandNumber=Random (0,9)
  ; here I should pusd 'myRandNumber' to the array
Msgbox (0,"",?); Here all my array elements should be displayed

Thanks for the help!

Link to comment
Share on other sites

Try the following:

Dim $array[$arrayLength]
For $loop=0 to $arrayLength-1
  $myRandNumber=Random (0,9)
  $array[$loop] = $myRandNumber
$string = ""
For $loop=0 to $arrayLength - 1
  $string = $string & $array[$loop] & " "
Msgbox (0,"",$string); Here all my array elements should be displayed


1. Not quite sure what you where trying to do with the $arrayLength=(1,20); statement. It isn't legal as is. I've replaced it with a single value

2. The loops go from 0 to $arrayLength - 1 because AutoIt arrays start at zero

3. AFAIK there is no statement to print out an array directly. I've added a loop to concatonate the array elements into a string for output

4. If you don't need $myRandNumber for any thing then you can simply assign directly to the array element (i.e. $array[$loop] = Random(0,9) )


Link to comment
Share on other sites

  • Developers

Thanx GrahamS, I got it.

I have another little question. :whistle:  The following returned an error. Why?

Dim $myArray [3]
For $loop=0 to 3
    $myRandNumber=Random (1,9)
    $myArray [$loop] = $myRandNumber

10x again...

Thats because from 0 to 3 is 4 steps.... B) Edited by JdeB

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

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

  • Recently Browsing   0 members

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