Jump to content

HOW TO: sequential variable = array


Recommended Posts

HI All,

Thanks in advance for your help!

If I'm reading and collecting unique values out of x arrays, how do I sequentially name "$aColUnique&$i" in the following example:

 

$rSort1 = "X:X" ; first  sort
$rSort2 = "A:A" ; second sort

Local  $aRowSort [] = [$rSort1,$rSort2]
$iRow =UBound($aRowSort)

For $i = 0 To $iRow  - 1
    $aColCollect =  _Excel_RangeRead($oWorkbook,Default,$aRowSort[$i])
    $aColUnique&$i = _ArrayUnique($aColCollect, Default, Default, Default, $ARRAYUNIQUE_NOCOUNT)
    _ArrayDisplay($aColUnique&$i,"$aRowSort")
Next

 

An alternative would be to add the ColUnique data onto the $aRowSort as another column. I attempted to do this, but it wouldn't add to the end of the column. I can revisit it if this new idea is dumb.

Edited by MrCheese
Link to comment
Share on other sites

Actually I was referring to sub arrays example:

For $i = 0 To UBound($aRowSort) - 1
     $aColCollect =  _Excel_RangeRead($oWorkbook,Default,$aRowSort[$i])
    _ArrayAdd($aColUnique, _ArrayUnique($aColCollect, Default, Default, Default, $ARRAYUNIQUE_NOCOUNT), 0, "|", @CRLF, 1)
Next

For $i = 0 To UBound($aColUnique) - 1
    _ArrayDisplay($aColUnique[$i])
    $aTmpArray = $aColUnique[$i]
    For $j = 0 To UBound($aTmpArray) - 1
        ConsoleWrite($aTmpArray[$j] & @CRLF)
    Next
Next

 

Link to comment
Share on other sites

i realised that I had to call it as a set array not attached to a looping variable as it the two $i values were referenced in different levels of a nested loop.

I'm sure there is a better way 

$aTmpArray0 = $aColUnique[0] ; setting temp0 arrays as the sub array0
$aTmpArray1 = $aColUnique[1] ;  setting temp1 array as the sub array1


For $u = 0 To UBound($aTmpArray0) - 1
    If $aTmpArray0[$u] = "" Then ContinueLoop
    $i = 0
    $rowval = $aRowSort[$i]
    $rowsort = $rowval & ":" & $rowval
    $nCol1 = _Excel_ColumnToNumber($rowval)
    _Excel_FilterSet($oWorkbook, Default, Default, $nCol1, $aTmpArray0[$u])
    $msg = "first filter: " & $aTmpArray0[$u]
    dbb()
    For $j = 0 To UBound($aTmpArray1) - 1
        If $aTmpArray1[$j] = "" Then ContinueLoop
        $i = 1
        $rowval = $aRowSort[$i]
        $rowsort = $rowval & ":" & $rowval
        $nCol1 = _Excel_ColumnToNumber($rowval)
        _Excel_FilterSet($oWorkbook, Default, Default, $nCol1, $aTmpArray1[$j])
        $msg = "first filter: " & $aTmpArray1[$j]
        dbb()
        Local $afilter = _Excel_FilterGet($oWorkbook)
        If $afilter[0][6] <= 1 Then ; location of filtered row count
            $msg = "skipping loop"
            dbb()
            ContinueLoop
        EndIf
        $sName = @ScriptDir & "\R1_" & $aTmpArray0[$u] & "_score_" & $aTmpArray1[$j] & ".xls"
        $msg = "saving"
        dbb()
        MakeCopy(1, $iRowT, $sName)
    Next
    _Excel_FilterSet($oWorkbook, Default, Default, 0)
Next

 

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