Jump to content

I'm Stumped!


Recommended Posts

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

:D:huh2::)

Triton
Link to comment
Share on other sites

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 ?

:D

:iamstupid:

Triton
Link to comment
Share on other sites

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!
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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 by Valik
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
 Share

  • Recently Browsing   0 members

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