Sign in to follow this  
Followers 0
CrewXp

Easy Question, is there a _ArrayCreate or Dim $array[0]?

2 posts in this topic

If I want to make a dynamic array (which I use A LOT), I have to do this:

Dim $array[1] ;Makes an array with an empty spot in it... Because I can't use $array[0] or just $array

_ArrayAdd($array,"blah")

_ArrayAdd($array,"blah2")

_ArrayAdd($array,"blah3")

_ArrayDelete($array,0 ;To delete the empty spot I made.

Is there any way to do this...?

_ArrayCreate($array)

_ArrayAdd($array,"blah")

So that I don't always have to delete that empty spot in the array?

Thanks

Share this post


Link to post
Share on other sites



Use your custom ArrayAdd function: example:

Func _Array0Add(ByRef $avArray, $vValue)
    If Not IsArray($avArray) Then Return SetError(1, 0, -1)
    If UBound($avArray, 0) <> 1 Then Return SetError(2, 0, -1)

    Local $iUBound = UBound($avArray)
    If $iUBound = 1 And $avArray[0] = 0 Then
        $avArray[0] = $vValue
    Else
        ReDim $avArray[$iUBound + 1]
        $avArray[$iUBound] = $vValue
    EndIf
    Return $iUBound
EndFunc  ;==>_Array0Add

This function will replace element 0 with the $vValue if the array has a single element and its value is 0

IMO - you better use $array[0] = "blah" instead of

_ArrayAdd($array,"blah")

_ArrayDelete($array,0)


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

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