Themistokles Posted June 25, 2008 Share Posted June 25, 2008 Hello, I need to create a bunch of arrays and want them to be initialized with 0 (because I do not know which is the value that would be assigned to each element of the array if I would just create it, maybe somebody can tell me) so I can determine which elements have actually been used (the ones that are not 0 at the beginning of each array). I've looked up the "Dim" function in the Keyword/Statement Reference and it says that I just have to type "Dim $Array[50]" and then something I do not understand. Is it "=0" or "[=0]" or "[0]" or something else? Of course I could just run a While Loop and initialize all arrays, but I need to create about 26 arrays and would like to save the time (and space) I would need for doing this. As I am going on holiday tomorrow and won't have access to the Internet for four weeks, I would be glad for an answer before, say, 23 o'clock my time, as I live in Germany this is the GMT+1 (or UTC+1) time. With best wishes Themistokles Link to comment Share on other sites More sharing options...
zorphnog Posted June 25, 2008 Share Posted June 25, 2008 You can always just write a function to initialize an array. Dim $a1[5], $a2[10], $a3[50], $a4[15] _InitializeArray($a1) _InitializeArray($a2) _InitializeArray($a3) _InitializeArray($a4) Func _InitializeArray(ByRef $aArray) Local $i, $iMax $iMax = UBound($aArray)-1 For $i=0 To $iMax $aArray[$i] = 0 Next EndFunc Link to comment Share on other sites More sharing options...
Themistokles Posted June 25, 2008 Author Share Posted June 25, 2008 Yes, that would be an option. Thank you. Link to comment Share on other sites More sharing options...
zorphnog Posted June 25, 2008 Share Posted June 25, 2008 Actually, after re-reading your original post. The default value for each array is: 0 or "" (depending on what kind of data you are storing). Either one of these will work. So as long as none of the data you are populating your arrays with matches 0 or "", then you should be fine with just declaring the arrays. Here's a little test for you. Dim $a1[5] $a1[1] = 3 $a1[2] = "h" For $i=0 To 4 If $a1[$i] = 0 Then ConsoleWrite($i & ": Data is unchanged (0)" & @LF) If $a1[$i] = "" Then ConsoleWrite($i & ': Data is unchanged ("")' & @LF) Next Notice index 2 evaluates true for the statement $a1[$i] = 0 because the value stored in the array is not a integer. Link to comment Share on other sites More sharing options...
Themistokles Posted June 25, 2008 Author Share Posted June 25, 2008 Ok, thank you very much. As I am going to sleep now I won't be able to answer any further post. Themistokles Link to comment Share on other sites More sharing options...
aslani Posted June 25, 2008 Share Posted June 25, 2008 @OP Have you tried looking at the Array.au3 UDF? I use that UDF all the time and I think the _ArrayCreate() function is something you're looking for. [font="Georgia"]Chances are, I'm wrong.[/font]HotKey trouble?Stringregexp GuideAutoIT Current Version Link to comment Share on other sites More sharing options...
YellowLab Posted June 26, 2008 Share Posted June 26, 2008 (edited) I believe _ArrayCreate was removed with the current version of AutoIt (3.2.12) due to new array handling. Bob Edited June 26, 2008 by YellowLab You can't see a rainbow without first experiencing the rain. Link to comment Share on other sites More sharing options...
aslani Posted June 26, 2008 Share Posted June 26, 2008 I believe _ArrayCreate was removed with the current version of AutoIt (3.2.12) due to new array handling.Bob_ArrayCreate() documentation has been removed. The function is still present but may be removed at a later time. Scripts should be updated to use the array initialization syntax built into AutoIt.Still there. [font="Georgia"]Chances are, I'm wrong.[/font]HotKey trouble?Stringregexp GuideAutoIT Current Version Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now