Jump to content

Search the Community

Showing results for tags 'redim'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • General
    • Announcements and Site News
    • Administration
  • AutoIt v3
    • AutoIt Help and Support
    • AutoIt Technical Discussion
    • AutoIt Example Scripts
  • Scripting and Development
    • Developer General Discussion
    • Language Specific Discussion
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Categories

  • AutoIt Team
    • Beta
    • MVP
  • AutoIt
    • Automation
    • Databases and web connections
    • Data compression
    • Encryption and hash
    • Games
    • GUI Additions
    • Hardware
    • Information gathering
    • Internet protocol suite
    • Maths
    • Media
    • PDF
    • Security
    • Social Media and other Website API
    • Windows
  • Scripting and Development
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Location


WWW


Interests

Found 3 results

  1. Alright, currently I'm trying to merge two loops: Local $aArray[99][13] For $iLoop = 1 to 100 $aArray[$iLoop - 1][0] = RegEnumKey("HKLM\SYSTEM\CurrentControlSet\Control\GraphicsDrivers\Configuration", $iLoop) If @error <> 0 Then ReDim $aArray[$iLoop - 1][13] ExitLoop EndIf Next For $iLoop1 = 0 to UBound($aArray, 1) - 1 For $iLoop2 = 1 to 12 $aArray[$iLoop1][$iLoop2] = RegEnumKey("HKLM\SYSTEM\CurrentControlSet\Control\GraphicsDrivers\Configuration\" & $aArray[$iLoop1][0], $iLoop2) If @error <> 0 Then ExitLoop Next Next into one. Here's what I have so far: Local $aArray[99][13] For $iLoop1 = 0 to UBound($aArray, 1) - 1 For $iLoop2 = 0 to 12 ConsoleWrite("Loop1 = " & $iLoop1 & ", Loop2 = " & $iLoop2 & @CRLF) If $iLoop2 = 0 Then $aArray[$iLoop1][0] = RegEnumKey("HKLM\SYSTEM\CurrentControlSet\Control\GraphicsDrivers\Configuration", $iLoop1 + 1) If @error <> 0 Then ReDim $aArray[$iLoop1 + 1][13] ExitLoop EndIf Else $aArray[$iLoop1][$iLoop2] = RegEnumKey("HKLM\SYSTEM\CurrentControlSet\Control\GraphicsDrivers\Configuration\" & $aArray[$iLoop1][0], $iLoop2) If @error <> 0 Then ExitLoop EndIf Next Next And it keeps error-ing out trying to exceed the dimension range of the array. Does the Loop not recheck the size of the array after the original check or am I doing something else wrong. Thanks.
  2. 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 ;==> _ArrayForceDimIn 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.
  3. Hi All, I'm still fairly new to this board, and just board search has helped a lot lately in general, requiring me not to post much. My Question now is, if I create an array (and more specifically a 2 dimensional array) that I'm checking, and using the "ReDim" function as needed to increase the size as need-be, do I need to delete the array at the end of it's scope to maintain memory management? I'm most accustomed to C++ with pointers and new-ing them into arrays, and the importance of deleting them at the end of the code. I as just wondering if their is a way to do this or if there is a Garbage collecting system in effect. I tried the old RTFM but there's nothing really on this topic and I felt I should ask to clarify this. Thanks for all your help!
×
×
  • Create New...