Jump to content

ReDim UDF


Nutster
 Share

Recommended Posts

In order to keep the values in a one-dimensional array when making it bigger, this UDF can fit the bill. Two- or three-dimensional versions could be created from the same basic idea.

AutoItSetOption("MustDeclareVars", 1)

Func DisplayArray(ByRef $ARRAY)
    Local $I, $MSG
 
    For $I = 0 To UBound($ARRAY) - 1
        $MSG = $MSG & ", " & $ARRAY[$I]
    Next
    $MSG = StringTrimLeft($MSG, 2)
    MsgBox(0, "Array", $MSG)
EndFunc ;==>DisplayArray

Func Min($V1, $V2)
    If IsArray($V1) Then
        SetError(1)
    ElseIf $V1 < $V2 Then
        Return $V1
    Else
        Return $V2
    EndIf
EndFunc ;==>Min

Func ReDim(ByRef $ARRAY, $NEWSIZE)
    If IsArray($ARRAY) And StringIsInt($NEWSIZE) Then;Make sure of correct types
        Local $TMP = $ARRAY, $I
        Dim $ARRAY[$NEWSIZE]
     
        For $I = 0 To Min(UBound($TMP), $NEWSIZE) - 1
            $ARRAY[$I] = $TMP[$I]
        Next
        For $I = $I To UBound($array)-1
            $ARRAY[$I] = ""
        Next
    EndIf
EndFunc ;==>ReDim

Dim $R[30], $I

For $I = 0 To 29
    $R[$I] = 100 - $I
Next

DisplayArray($R)

ReDim($R, 50)

DisplayArray($R)

David Nuttall
Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius

AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

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...