czardas

_ArrayForceDim

11 posts in this topic

#1 ·  Posted (edited)

A question came up regarding _ArrayTranspose(). Strictly speaking this function is only suitable for 2D arrays:  transposition of a 1D array should return the same array, or an error. Why? - because there is no second dimension available to make the transposition. The workaround for this is to force the return of a 2D array containing a single row, which is all well and good until you want to reverse the process.  Should the original 1D array be returned, or a 2D array containing a single column?

A Possible Solution

After some discussion in the MVP forum, I have concluded that this type of problem is more common than people are led to believe. The help file clearly states that ReDim does not allow you to modify the number of dimensions in an array, and nobody questions this. Here is a function (similar to ReDim) which allows you to return the first column of a 2D array as a 1D array (and similar changes). You can add, or remove, up to 5 dimensions. The maximum supported number of dimensions is 6. Arrays with more than 4 dimensions are very rare.

#include <Array.au3> ; For _ArrayDisplay

Global $aArray1D[5] = [10, 20, 30, 40, 50]
Global $aArray2D[3][5] = [[10, 20, 30, 40, 50], [11, 21, 31, 41, 51], [12, 22, 32, 42, 52]]
Global $aArray3D[3][4][2] = [[["000", "001"], ["010", "011"], ["020", "021"], ["030", "031"]], _
                           [["100", "101"], ["110", "111"], ["120", "121"], ["130", "131"]], _
                           [["200", "201"], ["210", "211"], ["220", "221"], ["230", "231"]]]

_ArrayForceDim($aArray3D, 2) ; Convert to 2D
_ArrayDisplay($aArray3D, '3D coverted to 2D')

_ArrayDisplay($aArray2D, "2D (before)")
_ArrayForceDim($aArray2D, 1)
_ArrayDisplay($aArray2D, "2D converted to 1D (after)")

_ArrayForceDim($aArray1D, 6) ; 1D converted to 6D
For $i = 0 To UBound($aArray1D, 1) -1
    ConsoleWrite($aArray1D[$i][0][0][0][0][0] & @LF)
Next

; #FUNCTION# ===================================================================================================================
; Name...........: _ArrayForceDim
; Description ...: Changes the size of an array by adding, or removing, dimensions.
; Syntax.........: _ArrayForceDim($aArray, $iDimensions)
; Parameters.....; $aArray - The original array.
;                  $iDimensions - The number of dimensions in the returned array.
; Return values .: Returns the modified array ByRef.
;                  Failure sets @error as follows:
;                  |@error = 1 The first parameter is not an array.
;                  |@error = 2 The requested array has more than 6 dimensions.
;                  |@error = 3 The original array has more than 6 dimensions.
; Author.........: czardas
; Comments ......; This function works for up to 6 dimensions.
;                  New dimensions are added at the end in a standard sequence: $aArray[7][6] may become $aArray[7][6][1]
;                  Dimensions are removed in reverse sequence: $aArray[7][6] will become $aArray[7]
; ==============================================================================================================================

Func _ArrayForceDim(ByRef $aArray, $iDimensions)
    If Not IsArray($aArray) Then Return SetError(1)

    $iDimensions = Int($iDimensions)
    If $iDimensions < 1 Or $iDimensions > 6 Then Return SetError(2)

    Local $iPreDims = UBound($aArray, 0) ; current number of dimensions
    If $iPreDims = $iDimensions Then Return ; no change
    If $iPreDims > 6 Then Return SetError(3) ; too many dimensions

    ; get the size of each original dimension
    Local $a[$iPreDims +1]
    For $i = 1 To $iPreDims
        $a[$i] = UBound($aArray, $i)
    Next

    ReDim $a [$iDimensions +1] ; modify the number of dimensions

    ; assign the size of each new dimension ...[1][1][1] etc...
    For $i = $iPredims + 1 To $iDimensions
        $a[$i] = 1
    Next

    Local $2 = 0, $3 = 0, $4 = 0, $5 = 0, $6 = 0 ; varibale names are associated with dimensions
    Local $sElement = '$aArray' & StringLeft('[$1][$2][$3][$4][$5][$6]', $iPredims * 4) ; to access the original array elements

    ; add or remove dimensions
    Switch $iDimensions
        Case 1
            Local $aNewArray[$a[1]]
            For $1 = 0 To $a[1] -1
                $aNewArray[$1] = Execute($sElement)
            Next

        Case 2
            Local $aNewArray[$a[1]][$a[2]]
            For $1 = 0 To $a[1] -1
                For $2 = 0 To $a[2] -1
                    $aNewArray[$1][$2] = Execute($sElement)
                Next
            Next

        Case 3
            Local $aNewArray[$a[1]][$a[2]][$a[3]]
            For $1 = 0 To $a[1] -1
                For $2 = 0 To $a[2] -1
                    For $3 = 0 To $a[3] -1
                        $aNewArray[$1][$2][$3] = Execute($sElement)
                    Next
                Next
            Next

        Case 4
            Local $aNewArray[$a[1]][$a[2]][$a[3]][$a[4]]
            For $1 = 0 To $a[1] -1
                For $2 = 0 To $a[2] -1
                    For $3 = 0 To $a[3] -1
                        For $4 = 0 To $a[4] -1
                            $aNewArray[$1][$2][$3][$4] = Execute($sElement)
                        Next
                    Next
                Next
            Next

        Case 5
            Local $aNewArray[$a[1]][$a[2]][$a[3]][$a[4]][$a[5]]
            For $1 = 0 To $a[1] -1
                For $2 = 0 To $a[2] -1
                    For $3 = 0 To $a[3] -1
                        For $4 = 0 To $a[4] -1
                            For $5 = 0 To $a[5] -1
                                $aNewArray[$1][$2][$3][$4][$5] = Execute($sElement)
                            Next
                        Next
                    Next
                Next
            Next

        Case 6
            Local $aNewArray[$a[1]][$a[2]][$a[3]][$a[4]][$a[5]][$a[6]]
            For $1 = 0 To $a[1] -1
                For $2 = 0 To $a[2] -1
                    For $3 = 0 To $a[3] -1
                        For $4 = 0 To $a[4] -1
                            For $5 = 0 To $a[5] -1
                                For $6 = 0 To $a[6] -1
                                    $aNewArray[$1][$2][$3][$4][$5][$6] = Execute($sElement)
                                Next
                            Next
                        Next
                    Next
                Next
            Next
    EndSwitch

    $aArray = $aNewArray
EndFunc ;==> _ArrayForceDim

In terms of expanding an array, this function is useful when you know how many dimensions are needed, but you don't know how large the array will eventually become. Dimensions are added with the minimum size.

Edited by czardas
1 person likes this

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Now for a more realistic example.

#include <Array.au3> ; For _ArrayDisplay

; create a list of subjects
Local $aSubjects = [['Art',     'Painting', 'Music',   'Drama',     'Dance'], _
                    ['Science', 'Maths',    'Physics', 'Chemistry', 'Biology' ], _
                    ['Sport',   'Football', 'Golf',    'Snooker',   'Chess']]

_ArrayDisplay($aSubjects)

; create an (out of sequence) table of data pertaining to gender
Local $aGender = [['Gender', 'Painting', 'Physics', 'Music', 'Chess', 'Drama', 'Dance', 'Biology', 'Football', 'Golf', 'Maths', 'Chemistry', 'Snooker'], _
                  ['Male',    2,          5,         2,       10,      3,       1,       5,         12,         4,      6,       5,           1], _
                  ['Female',  7,          1,         3,       0,       4,       10,      6,         8,          0,      6,       6,           1]]

_ArrayDisplay($aGender)

; let's add another dimension
_ArrayForceDim($aSubjects, 3)

; we want three tables stacked so...
ReDim $aSubjects [UBound($aSubjects, 1)] [UBound($aSubjects, 2)] [3]

; add data according to the given information
For $k = 1 To UBound($aGender, 2) -1
    For $i = 0 To UBound($aSubjects) -1
        For $j = 1 To UBound($aSubjects, 2) -1
            If $aSubjects[$i][$j][0] = $aGender[0][$k] Then
                $aSubjects[$i][$j][1] = $aGender[1][$k]
                $aSubjects[$i][$j][2] = $aGender[2][$k]
                ContinueLoop 2
            EndIf
        Next
    Next
Next

; let's check the better reorganized data
For $i = 0 To UBound($aSubjects) -1
    ConsoleWrite('Category = ' & $aSubjects[$i][0][0] & @LF)
    For $j = 1 To UBound($aSubjects, 2) -1
        ConsoleWrite('Boys attending '  & $aSubjects[$i][$j][0] & ' = ' & $aSubjects[$i][$j][1] & @LF & _
                     'Girls attending ' & $aSubjects[$i][$j][0] & ' = ' & $aSubjects[$i][$j][2] & @LF & @LF)
    Next
Next

; #FUNCTION# ===================================================================================================================
; Name...........: _ArrayForceDim
; Description ...: Changes the size of an array by adding, or removing, dimensions.
; Syntax.........: _ArrayForceDim($aArray, $iDimensions)
; Parameters.....; $aArray - The original array.
;                  $iDimensions - The number of dimensions in the returned array.
; Return values .: Returns the modified array ByRef.
;                  Failure sets @error as follows:
;                  |@error = 1 The first parameter is not an array.
;                  |@error = 2 The requested array has more than 6 dimensions.
;                  |@error = 3 The original array has more than 6 dimensions.
; Author.........: czardas
; Comments ......; This function works for up to 6 dimensions.
;                  New dimensions are added at the end in a standard sequence: $aArray[7][6] may become $aArray[7][6][1]
;                  Dimensions are removed in reverse sequence: $aArray[7][6] will become $aArray[7]
; ==============================================================================================================================

Func _ArrayForceDim(ByRef $aArray, $iDimensions)
    If Not IsArray($aArray) Then Return SetError(1)

    $iDimensions = Int($iDimensions)
    If $iDimensions < 1 Or $iDimensions > 6 Then Return SetError(2)

    Local $iPreDims = UBound($aArray, 0) ; current number of dimensions
    If $iPreDims = $iDimensions Then Return ; no change
    If $iPreDims > 6 Then Return SetError(3) ; too many dimensions

    ; get the size of each original dimension
    Local $a[$iPreDims +1]
    For $i = 1 To $iPreDims
        $a[$i] = UBound($aArray, $i)
    Next

    ReDim $a [$iDimensions +1] ; modify the number of dimensions

    ; assign the size of each new dimension ...[1][1][1] etc...
    For $i = $iPredims + 1 To $iDimensions
        $a[$i] = 1
    Next

    Local $2 = 0, $3 = 0, $4 = 0, $5 = 0, $6 = 0 ; varibale names are associated with dimensions
    Local $sElement = '$aArray' & StringLeft('[$1][$2][$3][$4][$5][$6]', $iPredims * 4) ; to access the original array elements

    ; add or remove dimensions
    Switch $iDimensions
        Case 1
            Local $aNewArray[$a[1]]
            For $1 = 0 To $a[1] -1
                $aNewArray[$1] = Execute($sElement)
            Next

        Case 2
            Local $aNewArray[$a[1]][$a[2]]
            For $1 = 0 To $a[1] -1
                For $2 = 0 To $a[2] -1
                    $aNewArray[$1][$2] = Execute($sElement)
                Next
            Next

        Case 3
            Local $aNewArray[$a[1]][$a[2]][$a[3]]
            For $1 = 0 To $a[1] -1
                For $2 = 0 To $a[2] -1
                    For $3 = 0 To $a[3] -1
                        $aNewArray[$1][$2][$3] = Execute($sElement)
                    Next
                Next
            Next

        Case 4
            Local $aNewArray[$a[1]][$a[2]][$a[3]][$a[4]]
            For $1 = 0 To $a[1] -1
                For $2 = 0 To $a[2] -1
                    For $3 = 0 To $a[3] -1
                        For $4 = 0 To $a[4] -1
                            $aNewArray[$1][$2][$3][$4] = Execute($sElement)
                        Next
                    Next
                Next
            Next

        Case 5
            Local $aNewArray[$a[1]][$a[2]][$a[3]][$a[4]][$a[5]]
            For $1 = 0 To $a[1] -1
                For $2 = 0 To $a[2] -1
                    For $3 = 0 To $a[3] -1
                        For $4 = 0 To $a[4] -1
                            For $5 = 0 To $a[5] -1
                                $aNewArray[$1][$2][$3][$4][$5] = Execute($sElement)
                            Next
                        Next
                    Next
                Next
            Next

        Case 6
            Local $aNewArray[$a[1]][$a[2]][$a[3]][$a[4]][$a[5]][$a[6]]
            For $1 = 0 To $a[1] -1
                For $2 = 0 To $a[2] -1
                    For $3 = 0 To $a[3] -1
                        For $4 = 0 To $a[4] -1
                            For $5 = 0 To $a[5] -1
                                For $6 = 0 To $a[6] -1
                                    $aNewArray[$1][$2][$3][$4][$5][$6] = Execute($sElement)
                                Next
                            Next
                        Next
                    Next
                Next
            Next
    EndSwitch

    $aArray = $aNewArray
EndFunc ;==> _ArrayForceDim

After organizing the data in a sensible way, you realize that you also need to store data from several different institutions. The 3rd dimension containing students needs to contain the names of institutions, and the number of students of each gender need to be placed in the fourth dimension. Since the data is quite well organized, you can simply add another dimension and overwrite the third dimension using the same method.

This is just an example of a way of coding using multidimensional arrays. More complex examples may involve modification to arrays in real time, according to new information; or greater (or less) detail may suddenly be needed. You may wish to work with a multidimensional array of main headings and only expand the number of dimensions occasionally: so as to preserve memory. You can delete the extra dimensions when you have finished with them - returning to the original array.

This is not the only way to organize data, but sometimes it might be a most suitable approach. The extra dimensions are available, so let's use them!

Edited by czardas

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I'm not quite ready to update the first post yet, but I have modified this by adding an optional parameter. When $bPush is set to true, and you increase the number of dimensions; instead of adding higher dimensions with minimum bounds, the original array structure is pushed upwards towards the higher dimensions and new lower dimensions are inserted in the vacated positions (left of the array declaration syntax). When reversing this process, the lower dimensions are deleted from the left of the array declaration syntax; and the array structure returns back to, or goes beyond, the original dimensions. Meh, just run the examples and you'll see what I mean!

#include <Array.au3>

; Example
Local $aData = ['Header 1','Header 2','Header 3','Header 4','Header 5','Header 6']
_ArrayDisplay($aData, "Original 1D")
_ArrayForceDim($aData, 2, True) ; Push the 1st dimension to the 2nd dimension
_ArrayDisplay($aData, "1D to 2D push")

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; Quick Test
Local $a2D = [[1,2,3],['a','b','c']]
_ArrayDisplay($a2D, "Quick Test")

_ArrayForceDim($a2D, 4, True) ; push the 1st and 2nd dimensions to the 3rd and 4th dimensions
MsgBox(0, "No of Dimensions", UBound($a2D, 0))

For $i = 0 To UBound($a2D, 1) - 1
    For $j = 0 To UBound($a2D, 2) - 1
        For $k = 0 To UBound($a2D, 3) - 1
            For $l = 0 To UBound($a2D, 4) - 1
                ConsoleWrite($a2D[$i][$j][$k][$l] & @LF)
            Next
        Next
    Next
Next

_ArrayForceDim($a2D, 2, True)
_ArrayDisplay($a2D, "4D to 2D reverse push")

_ArrayForceDim($a2D, 1, True)
_ArrayDisplay($a2D, "2D to 1D reverse push")

_ArrayForceDim($a2D, 2, True)
_ArrayDisplay($a2D, "1D to 2D push")

; the very first element always remains intact
_ArrayForceDim($a2D, 1)
_ArrayDisplay($a2D, "2D to 1D default")

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


; #FUNCTION# ===================================================================================================================
; Name...........: _ArrayForceDim
; Description ...: Changes the size of an array by adding, or removing, dimensions.
; Syntax.........: _ArrayForceDim($aArray, $iDimensions [, $iPush = False])
; Parameters.....; $aArray - The original array.
;                  $iDimensions - The number of dimensions in the returned array.
;                  $bPush - [Optional] If set to True, new dimensions are inserted, or removed from the left [see comments].
; Return values .: Returns the modified array ByRef.
;                  Failure sets @error as follows:
;                  |@error = 1 The first parameter is not an array.
;                  |@error = 2 The requested array has more than 7 dimensions.
;                  |@error = 3 The original array has more than 7 dimensions.
; Author.........: czardas
; Comments ......; This function works for up to 7 dimensions.
;                  By default, new dimensions are added to the right in a standard sequence: $aArray[7][6] ==> $aArray[7][6][1]
;                  Dimensions are removed in reverse sequence: $aArray[7][6] ==> $aArray[7]
;                  When the $bPush parameter is set to True, the original array will be pushed to higher dimensions:
;                  $aArray[7][6] ==> $aArray[1][7][6], or the process reversed: $aArray[7][6] ==> $aArray[6]
; ==============================================================================================================================

Func _ArrayForceDim(ByRef $aArray, $iDimensions, $bPush = False)
    If Not IsArray($aArray) Then Return SetError(1)

    $iDimensions = Int($iDimensions)
    If $iDimensions < 1 Or $iDimensions > 7 Then Return SetError(2)

    Local $iPreDims = UBound($aArray, 0) ; current number of dimensions
    If $iPreDims = $iDimensions Then Return ; no change
    If $iPreDims > 7 Then Return SetError(3) ; too many dimensions

    ; get the size of each original dimension
    Local $a[$iPreDims +1]
    For $i = 1 To $iPreDims
        $a[$i] = UBound($aArray, $i)
    Next

    Local $sElement = '[$1][$2][$3][$4][$5][$6][$7]' ; array syntax used to access the original array elements

    If $bPush Then ; prefix dimensions, or delete from the left
        Local $iOffset = Abs($iDimensions - $iPreDims)
        If $iPreDims > $iDimensions Then
            For $i = 1 To $iDimensions ; shift elements to lower indices
                $a[$i] = $a[$i + $iOffset]
            Next
            $sElement = '$aArray' & StringLeft('[0][0][0][0][0][0]', $iOffset * 3) & StringLeft($sElement, $iDimensions * 4)

        Else
            ReDim $a [$iDimensions +1] ; make space for more dimensions
            For $i = $iDimensions To $iOffset +1 Step -1 ; shift elements to higher indices
                $a[$i] = $a[$i - $iOffset]
            Next
            For $i = 1 To $iOffset ; assign the size of each additional dimension [1][1][1]... etc...
                $a[$i] = 1
            Next

            $sElement = '$aArray' & StringMid($sElement, 1 + $iOffset * 4, $iPredims * 4)
        EndIf

    Else ; Default behaviour = append dimensions, or delete from the right
        ReDim $a [$iDimensions +1] ; modify the number of dimensions

        For $i = $iPredims + 1 To $iDimensions ; assign the size of each new dimension ...[1][1][1] etc...
            $a[$i] = 1
        Next
        $sElement = '$aArray' & StringLeft($sElement, $iPredims * 4)

        Local $2 = 0, $3 = 0, $4 = 0, $5 = 0, $6 = 0, $7 = 0 ; required to reference new higher dimensions
    EndIf

    ; add or remove dimensions
    Switch $iDimensions
        Case 1
            Local $aNewArray[$a[1]]
            For $1 = 0 To $a[1] -1
                $aNewArray[$1] = Execute($sElement)
            Next

        Case 2
            Local $aNewArray[$a[1]][$a[2]]
            For $1 = 0 To $a[1] -1
                For $2 = 0 To $a[2] -1
                    $aNewArray[$1][$2] = Execute($sElement)
                Next
            Next

        Case 3
            Local $aNewArray[$a[1]][$a[2]][$a[3]]
            For $1 = 0 To $a[1] -1
                For $2 = 0 To $a[2] -1
                    For $3 = 0 To $a[3] -1
                        $aNewArray[$1][$2][$3] = Execute($sElement)
                    Next
                Next
            Next

        Case 4
            Local $aNewArray[$a[1]][$a[2]][$a[3]][$a[4]]
            For $1 = 0 To $a[1] -1
                For $2 = 0 To $a[2] -1
                    For $3 = 0 To $a[3] -1
                        For $4 = 0 To $a[4] -1
                            $aNewArray[$1][$2][$3][$4] = Execute($sElement)
                        Next
                    Next
                Next
            Next

        Case 5
            Local $aNewArray[$a[1]][$a[2]][$a[3]][$a[4]][$a[5]]
            For $1 = 0 To $a[1] -1
                For $2 = 0 To $a[2] -1
                    For $3 = 0 To $a[3] -1
                        For $4 = 0 To $a[4] -1
                            For $5 = 0 To $a[5] -1
                                $aNewArray[$1][$2][$3][$4][$5] = Execute($sElement)
                            Next
                        Next
                    Next
                Next
            Next

        Case 6
            Local $aNewArray[$a[1]][$a[2]][$a[3]][$a[4]][$a[5]][$a[6]]
            For $1 = 0 To $a[1] -1
                For $2 = 0 To $a[2] -1
                    For $3 = 0 To $a[3] -1
                        For $4 = 0 To $a[4] -1
                            For $5 = 0 To $a[5] -1
                                For $6 = 0 To $a[6] -1
                                    $aNewArray[$1][$2][$3][$4][$5][$6] = Execute($sElement)
                                Next
                            Next
                        Next
                    Next
                Next
            Next

        Case 7
            Local $aNewArray[$a[1]][$a[2]][$a[3]][$a[4]][$a[5]][$a[6]][$a[7]]
            For $1 = 0 To $a[1] -1
                For $2 = 0 To $a[2] -1
                    For $3 = 0 To $a[3] -1
                        For $4 = 0 To $a[4] -1
                            For $5 = 0 To $a[5] -1
                                For $6 = 0 To $a[6] -1
                                    For $7 = 0 To $a[7] -1
                                        $aNewArray[$1][$2][$3][$4][$5][$6][$7] = Execute($sElement)
                                    Next
                                Next
                            Next
                        Next
                    Next
                Next
            Next
    EndSwitch

    $aArray = $aNewArray
EndFunc ;==> _ArrayForceDim

The first element ([0], [0][0], [0][0][0], [0][0][0][0] etc...) will never be overwritten regardless of how this function is used. Also note that the conversion in the first example (of a 1D array to a 2D array with the 3rd parameter set to True) returns exactly the same result as when a 1D array is passed to _ArrayTranspose().

Inserting new dimensions mid-between existing dimensions is not on the radar; but prefixing (or appending) new dimensions to existing dimensions introduces another approach to working with arrays, currently unexplored by me.

Edited by czardas

Share this post


Link to post
Share on other sites
Quote

The help file clearly states that ReDim does not allow you to modify the number of dimensions in an array, and nobody questions this.

I did and still do!

I've been long advocating that an array containing, say, 24 elements should be REDIM-able at will and at no significant penalty to any array whose product of dimensions is 24. E.g. $a[24] <--> $a[12][2] <--> $a[1][24] <--> $a[3][8] <--> $a[4][2][3] <--> $a[2][1][3][1][2][1][2] and so on.

Transposition should also be an internal operation as well, essentially free on performance penalty either.  Of course transposition should be allowed for any combination of dimensions, the only burden being for users to get the transposition signature right and not mix up their own representation.

Finally, I find the limit of 16*1024*1024 elements well too low for many practical use cases.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

That's an interesting proposal, although quite a different approach. I suppose you would loop from low to high until you ran out of elements from either the source or the target array (Flood Fill). Transposition in higher dimensions seems tricky. It's that signature you mentioned that sounds rather scary. How many orientations to choose from? :frantics:

Share this post


Link to post
Share on other sites

Doing free array redimensionning is just dead easy and requires zero loop. It's just indices' game which can be carried out with a few lines of fast C[++] internal code. Look, say you declare an array like this: $a[24]

Then $a[9] is the 9 + 1 = 10th element in the array (see it as 1-based internally).
ReDim $a[3][8]
Then $a[1][5] is the ((1 * 3) + 5 + 1) = 9th element in the original array (untouched).
ReDim $a[4][2][3]
Then $a[2][0][1] is the ((2 * 2 * 3) + (0 * 2) + 1 + 1) = 14th element in the original array (still untouched).

This works even with dummy dimensions if needed, e.g. ReDim $a[3][1][2][1][4] and don't tell me that it would slow down AutoIt more than having to duplicate arrays element by element in nested loops with pedestrian AutoIt code, like we're curently forced to do.

Dummy dimensions ARE useful. Note that the conversion from a column-vector to a row-vector can be done without question: ReDim from $a[24] to $a[1][24].

For transposition: say that by convention dimensions are numbered from 1 upwards. Transpose($a, 3, 1, 2) would only reorder last redim indices, which can also be done internally very easily in fast code. Transposition and redimensionning are not the same operation.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Yep, just an indices game - similar to the one I play above - before assigning values at new locations (using loops).

I'm totally open to the practicalities of other implementations. The implementation I decided on here was influenced by both the question in GH&S and circumstances where I would have used this previously myself (if it had existed in AutoIt). It makes construction of complex multidimensional arrays easier; by allowing you to assign the main categories, or ID information, separate from the array contents. Headings and sub-headings can be added at any stage during construction, by pushing the array upwards towards higher dimensions (making space to accommodate). This is a subset of possible implementations, and your plan is another subset which overlaps mine to a degree.

The fact that _ArrayTranspose() with 1D arrays returns the same result as 1D to 2D (push) is simply down to algorithm collision (for want of a better term). I must say that I find what you have to say quite fascinating. The current limitation of AutoIt ReDim is not something that worries me so much though. I think fixing problems with numbers is a huge priority. Things like arrays are just icing on the cake (well, icing with a cherry :) ).

Edited by czardas

Share this post


Link to post
Share on other sites
2 hours ago, czardas said:

I think fixing problems with numbers is a huge priority. Things like arrays are just icing on the cake (well, icing with a cherry :) ).

[Indeed the new partial quote is useful]

I don't agree so much: issues with large integers is a marginal issue, idiosyncrasies between Ints and FPs we can relatively easily live with, but arrays are central to almost any serious script. Look at how many times you'd like to get a 2D array directly from a regexp, parsing a CSV or such. Regularly, the point is "how do I sort a 2D array by rows (not by column)", reformatting/rearranging data fetched from Excel or a database, etc.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Hmm, I guess you're right. It's not just big Integers though. the operators are doing some strange things. As you well know; multiplication and division are the same thing, or opposites, if you prefer. Okay, I know we can convert floats to integers and do lots of clever things to patch the maths. I would prefer if division was the true reverse of multiplication. It seems we are missing some basic axioms. Although I am not really so experienced in programming and perhaps what I ask is more complicated than I imagine.

We'll stick to discussing arrays then! :P

Edited by czardas

Share this post


Link to post
Share on other sites

Did you mean disgusting or dissecting?


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

None of my arrays are like that, at least I don't think they are. :tv_horror:

Edited by czardas

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

  • Similar Content

    • Dimmae
      By Dimmae
      Hello,
      at first: i'm new here, so please forgive me my mistakes, and show them to me, just that i can learn to do better in the future.
      Now to my Problem: i have an excel sheet, where i just need some columns for further actions, but i have no idea how to add single columns to a new array.
      I found the following code(the one i just added as a file) from 'water' in this forum, but i wont get how i could add multiple columns into a new array.
      The biggest problem in my situation is that i dont know the count of the rows i need for the array, i just got a fix number of rows, which is 4.
       
      Hope you can help me, and sry again for this 'unlucky illustration'.
       
      btw: how can i add code shown as code here, instead of posting it as a attached file?.
       
       
       
      autoit-select-column.au3
      defects.xlsx
    • czardas
      By czardas
      Haven't had much time to code recently. However the following thread inspired me.
      The debate about linear, parallel and binary search methods was rather interesting and, in an attempt to be diplomatic, I decided to combine @jchd's suggestion with @LarsJ's binary search example. I decided that the binary search algorithm required modification to make it more linear. As usual, 'if you invent something, it probably already exists and if it already exists, it exists for a reason'. My first attempt was not all that good. The code worked but was really a mess. I blame peer pressure (to post an example of a parallel search method).  I will delete that old code in due course.
      With a little memory jogging and a glance at the help file, the solution turned out to be quite easy: I just needed a better understanding of Euler. Further modification will be needed to work with more complicated unicode strings. The output could be returned as an array or a delimitered string. I'm not so interested in those details. I'm just going to post the algorithm for now and anyone, who wants to, can modify it to suit their needs. Both arrays must contain at least 1 element.
      Local $aFoo = [0,1,2,3,4,5,6,7,9,10,11,12,13,14,15,16,19,20,23,24,26,30,35,39,40,41] Local $aBar = [0,1,5,6,7,8,9,10,11,12,13,14,17,18,19,21,24,25,26,27,34,35,38,40] ParallelExponetialSearch($aFoo, $aBar) ; Compares two lists - returning positive matches. Each input array must be unique (individually) and in alphabetical order. Func ParallelExponetialSearch($aFoo, $aBar) Local $sFind, _ $iMin_F = -1, $iMax_F = UBound($aFoo) -1, $Lo_F = $iMin_F, $Hi_F, _ $iMin_B = -1, $iMax_B = UBound($aBar) -1, $Lo_B = $iMin_B, $Hi_B While $iMin_F < $iMax_F And $iMin_B < $iMax_B ; Toggle Arrays - Which array has most untested elements? This is the one we want to search next, ; so we can bypass more comparisons because (in theory) mismatches have a greater chance of being skipped. If $iMax_F - $iMin_F >= $iMax_B - $iMin_B Then ; $aFoo has more (or an equal number of) untested elements $Hi_F = $iMax_F $iMin_B += 1 $sFind = $aBar[$iMin_B] While $Lo_F < $Hi_F ; search $aFoo For $i = 0 To Floor(Log($Hi_F - $Lo_F) / Log(2)) $Lo_F = $iMin_F + 2^$i If $aFoo[$Lo_F] = $sFind Then $iMin_F = $Lo_F ; each match should be added to the output [perhaps an array] ConsoleWrite($sFind & " found at $aFoo[" & $Lo_F & "] = $aBar[" & $iMin_B & "]" & @LF) ExitLoop 2 ElseIf $aFoo[$Lo_F] > $sFind Then $Hi_F = $Lo_F -1 $iMin_F += Floor(2^($i -1)) $Lo_F = $iMin_F ContinueLoop 2 EndIf Next $iMin_F = $Lo_F ; minimum increment is one WEnd Else ; $aBar has more untested elements $Hi_B = $iMax_B $iMin_F += 1 $sFind = $aFoo[$iMin_F] While $Lo_B < $Hi_B ; search $aBar For $i = 0 To Floor(Log($Hi_B - $Lo_B) / Log(2)) $Lo_B = $iMin_B + 2^$i If $aBar[$Lo_B] = $sFind Then $iMin_B = $Lo_B ; each match should be added to the output [perhaps an array] ConsoleWrite($sFind & " found at $aFoo[" & $iMin_F & "] = $aBar[" & $Lo_B & "]" & @LF) ExitLoop 2 ElseIf $aBar[$Lo_B] > $sFind Then $Hi_B = $Lo_B -1 $iMin_B += Floor(2^($i -1)) $Lo_B = $iMin_B ContinueLoop 2 EndIf Next $iMin_B = $Lo_B ; minimum increment is one WEnd EndIf WEnd EndFunc ;==> ParallelExponetialSearch I hope this will be useful to someone. I believe it deserved a thread of its own!
    • RC86
      By RC86
      Afternoon!
      I have a requirement to return both a string and an array from a function so as a result I put them both into an array and returned that.  I can access them in their entirety after returning them but then I can't seem to access the array elements after this.  Should I be able to or is there a prettier way?
      #include <Array.au3> ;Memory info returned as a string and an array $memoryInfo = _getMemoryInfo() msgbox(0,"Memory Info",$memoryInfo[0]) _ArrayDisplay($memoryInfo[1],"Memory as an Array") Local $newArray[7] $memoryInfo[1] = $newArray msgbox(0,"Test element",$newArray[0]) _ArrayDisplay($newArray) Func _getMemoryInfo() Local $newArray[7] Local $array = MemGetStats() $newArray[0] = $array[0] ;% of memory in use $newArray[1] = Round($array[1]/1024 * 0.001,2) ;Total physical RAM $newArray[2] = Round($array[2]/1024 * 0.001,2) ;Availaible physical RAM $newArray[3] = Round($array[3]/1024 * 0.001,2) ;Total pagefile $newArray[4] = Round($array[4]/1024 * 0.001,2) ;Available pagefile $newArray[5] = Round($array[5]/1024 * 0.001,2) ;Total virtual $newArray[6] = Round($array[6]/1024 * 0.001,2) ;Available virtual $memoryUsage = $newArray[1] - $newarray[2] $pagefileUsage = $newArray[3] - $newarray[4] ;Output/Return Local $returnArray[2] $returnArray[0] = "Memory: " & $memoryUsage & " GB/" & $newArray[1] & " GB " & @CRLF & "Pagefile: " & $pagefileUsage & " GB/" & $newArray[3] & " GB " $returnArray[1] = $newArray return $returnArray EndFunc A bit messy but hopefully it's understandable what I'm trying to achieve.
      Thanks!
    • Jibberish
      By Jibberish
      I am having difficulties getting updated results from GUICtrlCreateInput. I wrote a small script to demonstrate what I am trying to do.
      This script reads a text file into an array and displays the Name and Number from the text file.
      The user can check a name and change the number, and the results are displayed in _ArrayDisplay.
      Only the Checked names are displayed in their original position. This is necessary for future
      plumbing.
      The problem with this script is the original number is returned, not the changed number. I cannot
      figure out how to get the updated number to be displayed.
      ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; This script reads a text file into an array and displays the Name and Number from the text file. ; The user can check a name and change the number, and the results are displayed in _ArrayDisplay. ; Only the Checked names are displayed in their original position. This is necessary for future ; plumbing. ; ; The problem with this script is the original number is returned, not the changed number. I cannot ; figure out how to get the updated number to be displayed. ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #include-once #include <MsgBoxConstants.au3> #include <array.au3> #include <Date.au3> #include <WinAPIFiles.au3> #include <AutoItConstants.au3> #include <Misc.au3> #include <File.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> Local $iMax = 6 ;Default number of Videos - 1 for the array counter Dim $aTextFile[$iMax][2] ; [start with 5 entries][Name, Number] Don't get confused! [Row][Column] Local $i = 0 Local $iLeft = 30 Local $iTop = 30 Local $sName Local $sNumber Local $aArray Local $iMaxCol = 5 Local $iRow = 0 Local $iCol = 0 Local $aNumberCount[$iMaxCol][2] $aArray1 = ReadFile() $aNamesNumbers = DisplayNames($aArray1) _ArrayDisplay($aNamesNumbers) ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; ReadFile() places the contents of the NameNumber.txt file in an array ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Func ReadFile() Local $sFileData = @ScriptDir & "\NameNumber.txt" Local $iStrReturn = 0 Local $aArrayFile Local $aTextFile[$iMaxCol][2] Local $aName Local $sCheckBox1 Const $iL = 10 ; Count from Left for GUI so all buttons line up Local $sFill Local $iA = 0, $iN = 0 ; Put the Names into an Array _FileReadToArray($sFileData, $aArrayFile) For $iA = 0 To $aArrayFile[0] ; Step through the array looking for Names If StringInStr($aArrayFile[$iA], "Name:") Then $aName = StringSplit($aArrayFile[$iA],":") $sFill = $aName[2] If UBound($aTextFile) <= $iRow Then ; Resize the array when $iRow is equal to the element count in the array to prevent subscript error ReDim $aTextFile[UBound($aTextFile) + 1][$iMaxCol] EndIf $aTextFile[$iRow][$iCol] = $sFill $iRow += 1 EndIf Next $iCol = 1 $iRow = 0 $sFill = "" For $iA = 1 To $aArrayFile[0] ; Step through the array looking for Numbers If StringInStr($aArrayFile[$iA], "Number:") Then $aName = StringSplit($aArrayFile[$iA],":") $sFill = $aName[2] If UBound($aTextFile) <= $iRow Then ; Resize the array when $iRow is equal to the element count in the array to prevent subscript error ReDim $aTextFile[UBound($aTextFile) + 1][$iMaxCol] EndIf $aTextFile[$iRow][$iCol] = $sFill $iRow += 1 EndIf Next Return $aTextFile EndFunc ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; Display the Name and Number ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Func DisplayNames($aArray1) Local $aName[$iMax] Local $aNumbers[$iMax] $iMMCount = UBound($aArray1) $iMMCount -=1 Local $iWidth = 300 Local $iLength = 300;$iMMCount * 30 GUISetFont(12) $hGUI = GUICreate("Edit / Update Number Test", $iWidth, $iLength, -1, -1) GUICtrlCreateLabel(" Name Number",1,5) ;$iTop += 30 ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; Display Name with a Checkbox. Only Checked Names should be saved. ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ For $i = 0 to $iMMCount Step 1 $sNameText = $aArray1[$i][0] $iNameLength = StringLen($sNameText) $aName[$i] = GUICtrlCreateCheckbox($sNameText,$iLeft, $iTop) $iTop += 30 Next ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; Display the number from the text file below each name. Allow the user to change the number and display the ; new number. ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $iLeft = 60 GUIStartGroup() $iTop = 28 For $i = 0 to $iMMCount Step 1 $sNumberText = $aArray1[$i][1] $aNumberCount[$i][1] = $sNumberText $aNumberCount[$i][0] = GUICtrlCreateInput($sNumberText,$iLeft, $iTop, 50,18, $GUI_DOCKAUTO) GUICtrlSetPos($aNumberCount[$i][0],200) $iTop += 30 Next ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; Read the checked names and (possibly updated) number ; ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ $iMMCount = UBound($aNumberCount) $iMMNewCount = $iMMCount - 1 Local $aGUICheckbox[$iMMCount] Local $aCheckedNameNumber[$iMMCount][2] $iLeft = 30 Local $idCloseGUI = GUICtrlCreateButton("Close",$iLeft, $iTop) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $idCloseGUI For $i = 0 To $iMMNewCount Step 1 Switch GUICtrlRead($aName[$i]) Case $GUI_CHECKED $aCheckedNameNumber[$i][0] = $aArray1[$i][0] Case $GUI_UNCHECKED EndSwitch Switch GUICtrlRead($aNumberCount[$i][0]) Case $aCheckedNameNumber[$i][1] = GUICtrlRead($aNumberCount[$i][1]) EndSwitch Next ExitLoop EndSwitch WEnd For $i = 0 to $iMMNewCount step 1 GUICtrlRead($aNumberCount[$i][0]) If $aCheckedNameNumber[$i][0] <> "" Then $aCheckedNameNumber[$i][1] = $aNumberCount[$i][1] EndIf Next GUIDelete($hGUI) Return $aCheckedNameNumber EndFunc This is the text file I am reading. If you want to try this out put the NameNumber.txt file in your script directory. It's attached to the post.
      * This is a dummy file with a Name and Number * The only purpose of this file is to read the updated Number. Name:Taggart Number:916 Name:Mongo Number:90 Name:Hedley Lamarr Number:22 Name:Bart Number:9999 Name:The Waco Kid Number:2244 If I change the number, the original number is displayed at the end, not the updated/modified number. I need the modified number to be displayed.
      Thanks in advance for any assistance!
      Jibberish
      NameNumber.txt
    • Jibberish
      By Jibberish
      I am working on a Video Player Test Script. I am reading a text file into a 3d array to be displayed in a GUI.
      Array Content:
      [x][0]FileName.mp4
      [x][1]UsageCount -> Up to a 4 digit number
      [x][2]EnableUsageCount (True/False)
      In the GUI the user can check the filename box, edit the number of usages and check EnableUsageCount to turn on the UsageCount control using the UsageCount number for the maximum number of plays.
      To make this easier to deal with I have removed the EnableUsageCount section, and am just concentrating on getting a method to put the edited (or unchanged) UsageCount in the array. Currently nothing is read into the array, due to my using the wrong method in the Case statement.
      Here are code snippets of what I am trying to do:
      ; Snippets from script ; I read the text file at the bottom and put the .mp4 filenames in $aManifest[x][0] and UsageCount in $aManifest[x][1] ; Then I create a GUI to display the .mp4 filenames with checkboxes and the UsageCount to the right. UsageCount is editable by the user. ; If the filename is checked, I want to read the filename into $aCheckedVideos[x][0] and the updated UsageCount in $aCheckedVideos[x][1] ; The GUICtrlRead($aVideoName[$i]) with Case $GUI_CHECKED & UNCHECKED works for the checkboxes ; This section puts the filenames in the GUI with a checkbox For $i = 0 to $iMMCount Step 1 $sMP4Text = $aManifest[$i][0] $iMP4Length = StringLen($sMP4Text) $aVideoName[$i] = GUICtrlCreateCheckbox($sMP4Text,$iLeft, $iTop) $iTop += 30 Next ; This section reads numbers from the Manifest array, and I want to be able to change the number and have them saved. ; So the Case $GUI_CHECKED & UNCHECKED won't work here, and I can't figure out what I should be doing here. For $i = 0 to $iMMCount Step 1 $sUsageText = $aManifest[$i][1] $aUsageCount[$i] = GUICtrlCreateInput($sUsageText,$iLeft, $iTop, 50,18, $GUI_DOCKAUTO) GUICtrlSetPos($aUsageCount[$i],200) $iTop += 30 Next While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $idCloseGUI For $i = 0 To $iMMNewCount Step 1 Switch GUICtrlRead($aVideoName[$i]) Case $GUI_CHECKED $aCheckedVideos[$i][0] = $aManifest[$i][0] ; If checked, I put the results into a two D array Case $GUI_UNCHECKED ; where Video Name is $aCheckedVideos[x][0] EndSwitch Switch GUICtrlRead($aUsageCounter[$i]) Case $GUI_CHECKED $aCheckedVideos[$i][1] = $aUsageCount[$i] ;I want to put the text (numbers) in $aCheckedVideos[x][1] Case $GUI_UNCHECKED ;but what is returned is blank, probably due to EndSwitch ; $GUI_CHECKED being the wrong thing. Next ExitLoop EndSwitch WEnd ;The txt file I'm reading has the following: ;~ /** Title #1: Big Buck Bunny 1080p **/ ;~ "Name": "Big Buck Bunny", ;~ "URI": "..\\MediaFiles\\bbb_1080_60s.mp4", ;~ "UsageCount": 9999, ;~ "URI": "..\\MediaFiles\\bbb_1080_60s_enc1.mp4", ;~ "UsageCount": 45, ;~ "URI": "..\\MediaFiles\\bbb_1080_60s_enc1.mp4", ;~ "UsageCount": 2, ;~ /** Title #2: Tears of Steel 4K **/ ;~ "Name": "Tears of Steel 4K", ;~ "URI": "..\\MediaFiles\\tos_4K_60s_HEVC.mp4", ;~ "UsageCount": 9876, ;~ "URI": "..\\MediaFiles\\tos_4K_60s_HEVC_enc2.mp4", ;~ "UsageCount": 0, ;~ "URI": "..\\MediaFiles\\tos_4K_60s_HEVC_enc2.mp4", ;~ "UsageCount": 5, I am certain that the section
                          Switch GUICtrlRead($aUsageCounter[$i])
                              Case $GUI_CHECKED
                                  $aCheckedVideos[$i][1] = $aUsageCount[$i]    ;I want to put the text (numbers) in $aCheckedVideos[x][1]
                              Case $GUI_UNCHECKED                                ;but what is returned is blank, probably due to
                          EndSwitch                                            ; $GUI_CHECKED being the wrong thing.

      is wrong, and this is what I am looking for help with. Instead of $GUI_CHECKED what should I be looking for?
      The worst part of this is I had this working late last night, and then lost my changes and cannot for the life of me remember how I had this working.
      Help is truly appreciated!
      Jibberish