Triton 0 Posted April 10, 2004 I'm getting an error in this code, I get this error on the second removal of a item. Any sugestions would be helpful. If guiread()= $nAdd Then If $m=1 Then guisetcontroldata($softlist,guiread($mylist)) $software[1] = guiread($mylist) $m=2 else $n=$n+1 guisetcontroldata($softlist,guiread($mylist)) $software[$n] = guiread($mylist) Endif EndIf if guiread()= $nRemove Then If guiread($softlist) <> "" Then $i=1 While $i <= $n If $software[$i] = guiread($softlist) then msgbox(0,"",$software[$i] & "=" & guiread($softlist)) Else $list = $list & "|" & $software[$i] msgbox(0,"","z=" & $z & " " & "i=" & $i) $soft[$z]=$software[$i] <----------------------- Error $z=$z+1 EndIf $i=$i+1 Wend $n=$n-1 $software = 0 $software = $soft $soft = 0 $x=1 While $x <= $n msgbox(0,"Software Array",$software[$x]) $x=$x+1 Wend If $n = 0 Then guisetcontroldata($softlist,"") Else guisetcontroldata($softlist,"") guisetcontroldata($softlist,$list) endif endif endIf Triton Share this post Link to post Share on other sites
Valik 478 Posted April 10, 2004 Off the top of my head, you're probably indexing out of bounds because you are going from 1 to $n instead of 0 to $n-1 which is the correct range for your array. Share this post Link to post Share on other sites
Triton 0 Posted April 12, 2004 Allright, I think I am confused! To Initialize an array is something like this = Dim $temp[10] This creates an array structure with ten indexes starting at 0 through 9 Soooo I can now have data in index 0 , 1 , 2, 3, 4, and so on. Now, how do I retreive the data properly in a for loop ? :iamstupid: Triton Share this post Link to post Share on other sites
CyberSlug 6 Posted April 12, 2004 Dim $temp[10] ; Code to populate (initialize) array goes here ; Prints out the data For $i = 0 To UBound($temp)-1 MsgBox(0,"", "Element " & $i & " is " & $temp[$i]) Next P.S. You can also use StringSplit to easily create and initialize an array. $temp = StringSplit("Jan,Feb,Mar,Apr,May,June,July,Aug,Sept,Oct,Nov,Dec") Note that if you use StringSplit, that index 0 contains a special value..... Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig! Share this post Link to post Share on other sites
Triton 0 Posted April 13, 2004 Dim $temp[10] ; Code to populate (initialize) array goes here ; Prints out the data For $i = 0 To UBound($temp)-1 MsgBox(0,"", "Element " & $i & " is " & $temp[$i]) Next oK Say I want to remove the data that is in $temp[4] and re-initialize the array with just 9 elements? Triton Share this post Link to post Share on other sites
Valik 478 Posted April 13, 2004 (edited) Haven't we been over this before or am I thinking of somebody else? Array's are statically allocated. You can't delete an element out of the middle and have the rest "drop down". In the future, there will probably be a ReDim function which can be used to resize an array, but I doubt it will allow you to arbitrarily select which elements get truncated when going to a smaller size. In fact, writing a single-dimensional redim function is quite easy to do and several people have posted code to do so at various points. If you MUST have a way to delete a random element from an array and have the rest drop down, it should be trivial to implement a function to do so. But I must admit, I don't know why you would want to do such a thing. I guess I'm just used to arrays in C/C++ where the ability to just delete a random element from an array would pretty much kill the program as pointers begin to reference invalid places. Edited April 13, 2004 by Valik Share this post Link to post Share on other sites