Sign in to follow this  
Followers 0
huldu

Another array question

8 posts in this topic

I was just wondering how do you "fill" up an array with different values?

I tried something simple just to try get the idea.

#include <array.au3>

$as_test = ''

For $x = 1 To 100
    $as_test = $x
Next

_ArrayDisplay($as_test, "test")

The above doesnt work at all, what i tried to do was to fill $as_test with values, saving them to an "array". But this isnt how it works right?


"I'm paper, rock is fine, nerf scissors!!!"

Share this post


Link to post
Share on other sites



#include <array.au3>

Dim $as_test[11]

For $x = 1 To 10
    $as_test[$x] = $x
Next

_ArrayDisplay($as_test, "test")


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#include <array.au3>

Dim $as_test[11]

For $x = 1 To 10
    $as_test[$x] = $x
Next

_ArrayDisplay($as_test, "test")
Ye i kinda figured you would use the $as_test[11], as you know how many variables will be saved into the array. I missed that out in the question sorry, lets assume we have no idea how many values will be put into the array :o

"I'm paper, rock is fine, nerf scissors!!!"

Share this post


Link to post
Share on other sites

I was just wondering how do you "fill" up an array with different values?

I tried something simple just to try get the idea.

#include <array.au3>

$as_test = ''

For $x = 1 To 100
    $as_test = $x
Next

_ArrayDisplay($as_test, "test")

The above doesnt work at all, what i tried to do was to fill $as_test with values, saving them to an "array". But this isnt how it works right?

close, but you're just re-using the same value. you have to have alist referenced by index number, etc like:

$as_test[0] = 1
$as_test[1] = 2

for your example, try something like:

#include<array.au3>; you have to include array.au3 to use _arraydisplay()
dim $as_test[100]; the 100 means there will be 100 elements, from 0 - 99
$as_test[0]=0
for $x = 1 to 99; autoit convention is to put the number of indexes into the 0th element, so start filling at 1
$as_test[$x] = $x
$as_test[0] = $as_test[0] + 1
next
_ArrayDisplay($as_test,"Test Array")

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Thanks for the fast responses, but i left out the thing "i dont know how many values will be added into the array". In the above examples we know how many values are to be added, but if that is unknown what is the trick? :o

Lets say ill go thru a file and want to save each line into an array. Since i dont know how many lines the file has, how would i then do? (im using a file as an example, but it could be anything really).

Edited by huldu

"I'm paper, rock is fine, nerf scissors!!!"

Share this post


Link to post
Share on other sites

Thank you, was just something like that i were looking for :o


"I'm paper, rock is fine, nerf scissors!!!"

Share this post


Link to post
Share on other sites

Thanks for the fast responses, but i left out the thing "i dont know how many values will be added into the array". In the above examples we know how many values are to be added, but if that is unknown what is the trick? :o

you can redim if necessary per iteration, OR if the array is being returned by a function like FileReadToArray() or StringSplit() then don't give it a dimension when you declare it...

example

#include<array.au3>
dim $as_test
$as_test = StringSplit("this,is,a,comma,delimited,string,that,will,be,in,your,array",",")
_ArrayDisplay($as_test,"Your array")

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

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