Jump to content

ReDim Confusion


nago
 Share

Recommended Posts

I'm having a bit of a blonde moment again, I was hoping someone here could clear this up for me.

I have an array with 40,000+ entries (It's a file list returned from _FileListToArray()) but only one column (With the filenames in them.)

I want to go ahead and add additional columns to this array so I can add some statistics about the files to them, but I have no idea how to add that additional column.

I looked up ReDim, but when trying to use it to resize my array, it wipes out all the data within it.

Can anyone give me a pointer as to the correct usage of ReDim in this circumstance?

Link to comment
Share on other sites

#include <file.au3>
Opt('MustDeclareVars', 1)

Dim $ArrFiles, $ArrFiles2, $nEntries, $ntmp, $txt = ''

$ArrFiles = _FileListToArray(@ScriptDir)

For $nEntries = 1 To $ArrFiles[0]
    $txt &= $ArrFiles[$nEntries] & @CRLF
Next

MsgBox(64, 'Title', $txt & @CRLF & @CRLF & $ArrFiles[0])

$ArrFiles2 = _FileListToArray('C:\WINDOWS', '*.exe')

ReDim $ArrFiles[$ArrFiles2[0]+$ArrFiles[0]]
$ntmp = 0

For $nEntries = $ArrFiles[0] To UBound($ArrFiles)-1
    $ntmp += 1
    $ArrFiles[$nEntries] = $ArrFiles2[$ntmp]
Next

$ArrFiles[0] += $ArrFiles2[0]-1
$txt = ''

For $nEntries = 1 To $ArrFiles[0]
    $txt &= $ArrFiles[$nEntries] & @CRLF
Next

MsgBox(64, 'Title', $txt & @CRLF & @CRLF & $ArrFiles[0])
Exit

Don't get confuse with this script all you need to know that ReDim just let you reallocate or reference your array to suit your needs, like more subscripts which old ones retain their values or change how metrics' columns or rows get reference, i.e. $Arr[10][20] ---> ReDim $Arr[5][40] etc..

Edited by Authenticity
Link to comment
Share on other sites

Try This :

#include <File.au3>
#include <Array.au3>
Opt('MustDeclareVars', 1)

Dim $ArrFiles

$ArrFiles = _FileListToArray(@ScriptDir)
_ArrayDisplay($ArrFiles)
$ArrFiles = _ArrayAdd_Column($ArrFiles)
_ArrayDisplay($ArrFiles)
$ArrFiles = _ArrayAdd_Column($ArrFiles)
_ArrayDisplay($ArrFiles)

Func _ArrayAdd_Column($Array)
    Local $aTemp[UBound($Array)][UBound($Array, 0) + 1]
    For $i = 0 To UBound($Array) - 1
        For $j = 0 To UBound($Array, 0) - 1
            If UBound($Array, 0) = 1 Then $aTemp[$i][0] = $Array[$i]
            If UBound($Array, 0) > 1 Then $aTemp[$i][$j] = $Array[$i][$j]
        Next
    Next
    Return $aTemp
EndFunc  ;==>_ArrayAdd_Column
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...