Sign in to follow this  
Followers 0
Champak

Trying to subsort 2nd Colum of 2 Dimension array

9 posts in this topic

#1 ·  Posted (edited)

Title says it. First D is date(I have that taken care of), 2nd D is time. Here is what I have. I found the time sort (commented out at bottom), but don't know how to implement it as a subsort for my array.

#include-once
;#include<Array2d.au3>
#include<Array.au3>
#include<string.au3>
global $avArray[10][4]
#Region
$avArray[0][0] = "10/20/2008"
$avArray[1][0] = "10/14/2008"
$avArray[2][0] = "08/21/2008"
$avArray[3][0] = "08/14/2005";----------->Check for subsort
$avArray[4][0] = "08/14/2005";----------->Check for subsort
$avArray[5][0] = "12/24/2007"
$avArray[6][0] = "09/18/2007"
$avArray[7][0] = "05/23/2006"
$avArray[8][0] = "02/25/2008";----------->Check for subsort
$avArray[9][0] = "02/25/2008";----------->Check for subsort

$avArray[0][1] = "6:47"
$avArray[1][1] = "8:23"
$avArray[2][1] = "22:46"
$avArray[3][1] = "11:36";----------->Check for subsort
$avArray[4][1] = "9:40";----------->Check for subsort
$avArray[5][1] = "2:41"
$avArray[6][1] = "4:11"
$avArray[7][1] = "6:20"
$avArray[8][1] = "15:50";----------->Check for subsort
$avArray[9][1] = "7:46";----------->Check for subsort

$avArray[0][2] = "Something 1"
$avArray[1][2] = "Something 2"
$avArray[2][2] = "Something 3"
$avArray[3][2] = "Something 4"
$avArray[4][2] = "Something 5"
$avArray[5][2] = "Something 6"
$avArray[6][2] = "Something 7"
$avArray[7][2] = "Something 8"
$avArray[8][2] = "Something 9"
$avArray[9][2] = "Something 10"

$avArray[0][3] = "Another 1"
$avArray[1][3] = "Another 2"
$avArray[2][3] = "Another 3"
$avArray[3][3] = "Another 4"
$avArray[4][3] = "Another 5"
$avArray[5][3] = "Another 6"
$avArray[6][3] = "Another 7"
$avArray[7][3] = "Another 8"
$avArray[8][3] = "Another 9"
$avArray[9][3] = "Another 10"
#EndRegion

_ArrayDisplay($avArray)
For $i = 0 To UBound($avArray) - 1
    $Var1 = StringReplace($avArray[$i][0], "/", "")
    $MMDD = StringLeft($Var1, 4)
    $YYYY = StringTrimLeft($Var1, 4)
    $Var2 = _StringInsert($YYYY, $MMDD, 4)
    _ArraySwap($avArray[$i][0], $Var2)
Next
;_ArraySort($avArray, 0, 0, 0, 1)
_ArraySort($avArray)
For $i = 0 To UBound($avArray) - 1
    $Var1 = $avArray[$i][0]
    $YYYY = StringLeft($Var1, 4)
    $MMDD = StringTrimLeft($Var1, 4)
    $Var2 = _StringInsert($MMDD, $YYYY, 4)
    $Var3 = _StringInsert($Var2, "/", 2)
    $Var3 = _StringInsert($Var3, "/", 5)
    _ArraySwap($avArray[$i][0], $Var3)
Next
_ArrayDisplay($avArray, "First Sort")


#cs
;=======================================================TIME SORT
Func _Time_ArraySort(ByRef $a_Array, $i_Decending = 0, $i_Base = 0, $i_UBound = 0, $i_Dim = 1, $i_SortIndex = 0)
    Local $A_Size, $Gap, $Count, $Temp, $C_Dim
    Local $b_ExchangeValues = 0
    Local $IsChanged = 0

    ; Set to ubound when not specified
    If $i_UBound < 1 Then $i_UBound = UBound($a_Array) - 1

    If UBound($a_Array) <= $i_UBound Or Not IsNumber($i_UBound) Then
        SetError(1)
        Return 0
    EndIf
    ; Shell sort array
    $A_Size = $i_UBound
    $Gap = Int($A_Size / 2)
    $b_ExchangeValues = 0
    $IsChanged = 0
    ;
    While $Gap <> 0
        $IsChanged = 0
        For $Count = $i_Base To ($A_Size - $Gap)
            $b_ExchangeValues = 0
            If $i_Dim = 1 Then
                If $i_Decending <> 1 Then; sort array Ascending
                    If _Helper_TimeToTicks($a_Array[$Count]) > _Helper_TimeToTicks($a_Array[$Count + $Gap]) Then
                        $b_ExchangeValues = 1
                    EndIf
                Else ; sort array Descending
                    If _Helper_TimeToTicks($a_Array[$Count]) < _Helper_TimeToTicks($a_Array[$Count + $Gap]) Then
                        $b_ExchangeValues = 1
                    EndIf
                EndIf
                If ($b_ExchangeValues) Then
                    $Temp = $a_Array[$Count]
                    $a_Array[$Count] = $a_Array[$Count + $Gap]
                    $a_Array[$Count + $Gap] = $Temp
                    $IsChanged = 1
                EndIf
            Else
                If $i_Decending <> 1 Then; sort array Ascending
                    If _Helper_TimeToTicks($a_Array[$Count][$i_SortIndex]) > _Helper_TimeToTicks($a_Array[$Count + $Gap][$i_SortIndex]) Then
                        $b_ExchangeValues = 1
                    EndIf
                Else ; sort array Descending
                    If _Helper_TimeToTicks($a_Array[$Count][$i_SortIndex]) < _Helper_TimeToTicks($a_Array[$Count + $Gap][$i_SortIndex]) Then
                        $b_ExchangeValues = 1
                    EndIf
                EndIf
                If ($b_ExchangeValues) Then
                    For $C_Dim = 0 To $i_Dim - 1
                        $Temp = $a_Array[$Count][$C_Dim]
                        $a_Array[$Count][$C_Dim] = $a_Array[$Count + $Gap][$C_Dim]
                        $a_Array[$Count + $Gap][$C_Dim] = $Temp
                        $IsChanged = 1
                    Next
                EndIf
            EndIf
        Next
        ; If no changes were made to array, decrease $gap size
        If $IsChanged = 0 Then
            $Gap = Int($Gap / 2)
        EndIf
    WEnd
    Return 1
EndFunc   ;==>_Time_ArraySort

Func _Helper_TimeToTicks($arg)
    Local $hours, $mins, $secs, $i
    Local $values = StringSplit($arg, ":")
    If $values[0] = 2 Then
        $hours = 0
        $mins = $values[1]
        $secs = $values[2]
    ElseIf $values[0] = 3 Then
        $hours = $values[1]
        $mins = $values[2]
        $secs = $values[3]
    EndIf
    Return _TimeToTicks($hours, $mins, $secs)
EndFunc   ;==>_Helper_TimeToTicks
;=======================================================TIME SORT
#ce
Edited by Champak

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

First, that is NOT a 4D array. It is a 2D array with four elements in the second index/dimension. A 4D array would have references like: $avArray[2][1][3][6]

If your problem is the single/two-digit sorting then convert the value to two-digit numbers with leading zeros using StringFormat() before sorting. That way "7:46" would become "07:46" and would then correctly sort before "15:50".

muttley

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Title says it. First D is date(I have that taken care of), 2nd D is time. Here is what I have. I found the time sort (commented out at bottom), but don't know how to implement it as a subsort for my array.

#include-once
;#include<Array2d.au3>
#include<Array.au3>
#include<string.au3>
global $avArray[10][4]
#Region
$avArray[0][0] = "10/20/2008"
$avArray[1][0] = "10/14/2008"
$avArray[2][0] = "08/21/2008"
$avArray[3][0] = "08/14/2005";----------->Check for subsort
$avArray[4][0] = "08/14/2005";----------->Check for subsort
$avArray[5][0] = "12/24/2007"
$avArray[6][0] = "09/18/2007"
$avArray[7][0] = "05/23/2006"
$avArray[8][0] = "02/25/2008";----------->Check for subsort
$avArray[9][0] = "02/25/2008";----------->Check for subsort

$avArray[0][1] = "6:47"
$avArray[1][1] = "8:23"
$avArray[2][1] = "22:46"
$avArray[3][1] = "11:36";----------->Check for subsort
$avArray[4][1] = "9:40";----------->Check for subsort
$avArray[5][1] = "2:41"
$avArray[6][1] = "4:11"
$avArray[7][1] = "6:20"
$avArray[8][1] = "15:50";----------->Check for subsort
$avArray[9][1] = "7:46";----------->Check for subsort

$avArray[0][2] = "Something 1"
$avArray[1][2] = "Something 2"
$avArray[2][2] = "Something 3"
$avArray[3][2] = "Something 4"
$avArray[4][2] = "Something 5"
$avArray[5][2] = "Something 6"
$avArray[6][2] = "Something 7"
$avArray[7][2] = "Something 8"
$avArray[8][2] = "Something 9"
$avArray[9][2] = "Something 10"

$avArray[0][3] = "Another 1"
$avArray[1][3] = "Another 2"
$avArray[2][3] = "Another 3"
$avArray[3][3] = "Another 4"
$avArray[4][3] = "Another 5"
$avArray[5][3] = "Another 6"
$avArray[6][3] = "Another 7"
$avArray[7][3] = "Another 8"
$avArray[8][3] = "Another 9"
$avArray[9][3] = "Another 10"
#EndRegion

_ArrayDisplay($avArray)
For $i = 0 To UBound($avArray) - 1
    $Var1 = StringReplace($avArray[$i][0], "/", "")
    $MMDD = StringLeft($Var1, 4)
    $YYYY = StringTrimLeft($Var1, 4)
    $Var2 = _StringInsert($YYYY, $MMDD, 4)
    _ArraySwap($avArray[$i][0], $Var2)
Next
;_ArraySort($avArray, 0, 0, 0, 1)
_ArraySort($avArray)
For $i = 0 To UBound($avArray) - 1
    $Var1 = $avArray[$i][0]
    $YYYY = StringLeft($Var1, 4)
    $MMDD = StringTrimLeft($Var1, 4)
    $Var2 = _StringInsert($MMDD, $YYYY, 4)
    $Var3 = _StringInsert($Var2, "/", 2)
    $Var3 = _StringInsert($Var3, "/", 5)
    _ArraySwap($avArray[$i][0], $Var3)
Next
_ArrayDisplay($avArray, "First Sort")


#cs
;=======================================================TIME SORT
Func _Time_ArraySort(ByRef $a_Array, $i_Decending = 0, $i_Base = 0, $i_UBound = 0, $i_Dim = 1, $i_SortIndex = 0)
    Local $A_Size, $Gap, $Count, $Temp, $C_Dim
    Local $b_ExchangeValues = 0
    Local $IsChanged = 0

    ; Set to ubound when not specified
    If $i_UBound < 1 Then $i_UBound = UBound($a_Array) - 1

    If UBound($a_Array) <= $i_UBound Or Not IsNumber($i_UBound) Then
        SetError(1)
        Return 0
    EndIf
    ; Shell sort array
    $A_Size = $i_UBound
    $Gap = Int($A_Size / 2)
    $b_ExchangeValues = 0
    $IsChanged = 0
    ;
    While $Gap <> 0
        $IsChanged = 0
        For $Count = $i_Base To ($A_Size - $Gap)
            $b_ExchangeValues = 0
            If $i_Dim = 1 Then
                If $i_Decending <> 1 Then; sort array Ascending
                    If _Helper_TimeToTicks($a_Array[$Count]) > _Helper_TimeToTicks($a_Array[$Count + $Gap]) Then
                        $b_ExchangeValues = 1
                    EndIf
                Else ; sort array Descending
                    If _Helper_TimeToTicks($a_Array[$Count]) < _Helper_TimeToTicks($a_Array[$Count + $Gap]) Then
                        $b_ExchangeValues = 1
                    EndIf
                EndIf
                If ($b_ExchangeValues) Then
                    $Temp = $a_Array[$Count]
                    $a_Array[$Count] = $a_Array[$Count + $Gap]
                    $a_Array[$Count + $Gap] = $Temp
                    $IsChanged = 1
                EndIf
            Else
                If $i_Decending <> 1 Then; sort array Ascending
                    If _Helper_TimeToTicks($a_Array[$Count][$i_SortIndex]) > _Helper_TimeToTicks($a_Array[$Count + $Gap][$i_SortIndex]) Then
                        $b_ExchangeValues = 1
                    EndIf
                Else ; sort array Descending
                    If _Helper_TimeToTicks($a_Array[$Count][$i_SortIndex]) < _Helper_TimeToTicks($a_Array[$Count + $Gap][$i_SortIndex]) Then
                        $b_ExchangeValues = 1
                    EndIf
                EndIf
                If ($b_ExchangeValues) Then
                    For $C_Dim = 0 To $i_Dim - 1
                        $Temp = $a_Array[$Count][$C_Dim]
                        $a_Array[$Count][$C_Dim] = $a_Array[$Count + $Gap][$C_Dim]
                        $a_Array[$Count + $Gap][$C_Dim] = $Temp
                        $IsChanged = 1
                    Next
                EndIf
            EndIf
        Next
        ; If no changes were made to array, decrease $gap size
        If $IsChanged = 0 Then
            $Gap = Int($Gap / 2)
        EndIf
    WEnd
    Return 1
EndFunc   ;==>_Time_ArraySort

Func _Helper_TimeToTicks($arg)
    Local $hours, $mins, $secs, $i
    Local $values = StringSplit($arg, ":")
    If $values[0] = 2 Then
        $hours = 0
        $mins = $values[1]
        $secs = $values[2]
    ElseIf $values[0] = 3 Then
        $hours = $values[1]
        $mins = $values[2]
        $secs = $values[3]
    EndIf
    Return _TimeToTicks($hours, $mins, $secs)
EndFunc   ;==>_Helper_TimeToTicks
;=======================================================TIME SORT
#ceoÝ÷ Ûú®¢×º-zØb±û§rبÊ&zئy¨("Ü"[(®Ö§Ø6«­¬®²)àºhÝÊ%ºiìb¬¥u·nW­¢jü¢¶Ú,º+^Ê«ç°i®Únz)©®Þvêh»­Ù¶l§yçljÛazئx±©mÈ4¬j'r¢ì"YÞyÛh­çè®f­¶­g¯j[²ÚuÙ^iا7«¢Ëhëmé­¢Ê+µÊ+­ç-&®¶­sb6æ6ÇVFRfÇC¶'&æS2fwC° ¤gVæ2ô×'&6÷'B'&Vbb33c¶d'&Âb33c¶ôFW66VæFærÒÂb33c¶7F'BÒÂb33c¶6öÃÒÂb33c¶6öÃ"ÒÂb33c¶6öÃ2Ò Æö6Âb33c¶VæBÒ Æö6Âb33c¶Æ7E&÷rÒ  ²6÷'BöâFRf'7B6öÇVÖà ô'&6÷'Bb33c¶d'&Âb33c¶ôFW66VæFærÂb33c¶7F'BÂb33c¶VæBÂb33c¶6öà  ²f÷"V6w&÷WöbfÇVW2âFRf'7B6öÇVÖâ6÷'BFR6V6öæB6öÇVÖà bb33c¶6öÃ"fwC²FVà b33c¶7F'BÒÓ b33c¶Æ7E&÷rÒb33c¶d'&³Õ³Ð f÷"b33c¶ÒFòb33c¶Æ7E&÷p 7vF6b33c¶ 66R bb33c¶fÇC²fwC²b33c¶Æ7E&÷rFVà bb33c¶d'&²b33c¶Õ²b33c¶6öÃÒfÇC²fwC²b33c¶d'&²b33c¶²Õ²b33c¶6öÃÒFVà b33c¶7F'BÒb33c¶ b33c¶VæBÒb33c¶7F'@ VÇ6P b33c¶7F'BÒ b33c¶VæBÒb33c¶7F'@ VæD` VæD` 66Rb33c¶Æ7E&÷p b33c¶VæBÒb33c¶Æ7E&÷p bb33c¶7F'BfÇC²fwC²b33c¶VæBFVà ô'&6÷'Bb33c¶d'&Âb33c¶ôFW66VæFærÂb33c¶7F'BÂb33c¶VæBÂb33c¶6öÃ" VæD` 66RVÇ6P bb33c¶d'&²b33c¶Õ²b33c¶6öÃÒfÇC²fwC²b33c¶d'&²b33c¶²Õ²b33c¶6öÃÒFVà b33c¶VæBÒb33c¶ bb33c¶7F'BfÇC²fwC²b33c¶VæBFVà ô'&6÷'Bb33c¶d'&Âb33c¶ôFW66VæFærÂb33c¶7F'BÂb33c¶VæBÂb33c¶6öÃ" VæD` b33c¶7F'BÒb33c¶² b33c¶VæBÒb33c¶7F'@ VÇ6P b33c¶VæBÒb33c¶ VæD` VæE7vF6 æW@ VæD`  ²f÷"V6w&÷WöbfÇVW2âFR6V6öæB6öÇVÖâ6÷'BFRF&B6öÇVÖà bb33c¶6öÃ2fwC²FVà b33c¶7F'BÒÓ f÷"b33c¶ÒFòb33c¶Æ7E&÷p 7vF6b33c¶ 66R bb33c¶fÇC²fwC²b33c¶Æ7E&÷rFVà bb33c¶d'&²b33c¶Õ²b33c¶6öÃÒfÇC²fwC²b33c¶d'&³%Õ²b33c¶6öÃÒ÷"b33c¶d'&²b33c¶Õ²b33c¶6öÃ%ÒfÇC²fwC²b33c¶d'&³%Õ²b33c¶6öÃ%ÒFVà b33c¶7F'BÒ  b33c¶VæBÒb33c¶7F'@ VÇ6P b33c¶7F'BÒ b33c¶VæBÒb33c¶7F'@ VæD` VæD` 66Rb33c¶Æ7E&÷p b33c¶VæBÒb33c¶Æ7E&÷p bb33c¶7F'BfÇC²fwC²b33c¶VæBFVà ô'&6÷'Bb33c¶d'&Âb33c¶ôFW66VæFærÂb33c¶7F'BÂb33c¶VæBÂb33c¶6öÃ2 VæD` 66RVÇ6P bb33c¶d'&²b33c¶Õ²b33c¶6öÃÒfÇC²fwC²b33c¶d'&²b33c¶²Õ²b33c¶6öÃÒ÷"b33c¶d'&²b33c¶Õ²b33c¶6öÃ%ÒfÇC²fwC²b33c¶d'&²b33c¶²Õ²b33c¶6öÃ%ÒFVà b33c¶VæBÒb33c¶ bb33c¶7F'BfÇC²fwC²b33c¶VæBFVà ô'&6÷'Bb33c¶d'&Âb33c¶ôFW66VæFærÂb33c¶7F'BÂb33c¶VæBÂb33c¶6öÃ2 VæD` b33c¶7F'BÒb33c¶² b33c¶VæBÒb33c¶7F'@ VÇ6P b33c¶VæBÒb33c¶ VæD` VæE7vF6 æW@ VæD`¤VæDgVæ2³ÓÒfwCµô×'&6÷'

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

@PsaltyDS

OK. I always thought a column was a dimension, hence 4 columns = 4D, and elements are items/values within an array. Now I know.

As for sorting the time, I know putting a leading zero will allow me to sort it "correctly", but that is why I included the commented out function at the bottom of the OP, because it doesn't require a leading zero. But if you are saying that because it is "better", then I will follow you and go that route; but knowing that still doesn't help me in subsorting(if I'm using that word correctly) the second column.

@Bowmore

I'm getting an error:

CODE
C:\Script\test2.au3 (106) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

If ($avArray[$i][$iCol1] <> $avArray[$i + 1][$iCol1]) Then

If ($avArray[$i][$iCol1] <> ^ ERROR

I'm using it like:

_MyArraySort($avArray, 0, 0, 0, 1)

Assuming I'm using it correctly, it should sort the date in the 1st column, then subsort the time in the 2nd colum in respect to the 1st (Already took into consideration your function requires the leading zero on the time).

EDIT: Renamed thread according to PsaltyDS correction.

Edited by Champak

Share this post


Link to post
Share on other sites

@PsaltyDS

OK. I always thought a column was a dimension, hence 4 columns = 4D, and elements are items/values within an array. Now I know.

As for sorting the time, I know putting a leading zero will allow me to sort it "correctly", but that is why I included the commented out function at the bottom of the OP, because it doesn't require a leading zero. But if you are saying that because it is "better", then I will follow you and go that route; but knowing that still doesn't help me in subsorting(if I'm using that word correctly) the second column.

This was what I meant. It does not require changing the data in the input array:
#include<Array.au3>

; Create input array
Global $avInput[10][4] = [["10/20/2008", "6:47", "Something 1", "Another 1"], _
        ["10/14/2008", "8:23", "Something 2", "Another 2"], _
        ["08/21/2008", "22:46", "Something 3", "Another 3"], _
        ["08/14/2005", "11:36", "Something 4", "Another 4"], _
        ["08/14/2005", "9:40", "Something 5", "Another 5"], _
        ["12/24/2007", "2:41", "Something 6", "Another 6"], _
        ["09/18/2007", "4:11", "Something 7", "Another 7"], _
        ["05/23/2006", "6:20", "Something 8", "Another 8"], _
        ["02/25/2008", "15:50", "Something 9", "Another 9"], _
        ["02/25/2008", "7:46", "Something 10", "Another 10"]]
_ArrayDisplay($avInput, "$avInput")

; Create index array to be sorted
Global $avTempSort[UBound($avInput)][2]
For $i = 0 To UBound($avInput) - 1
    $avTempSort[$i][0] = $i
    $avTempDate = StringSplit($avInput[$i][0], "/"); Date must be MM/DD/YYY
    $avTempTime = StringSplit($avInput[$i][1], ":"); Time must be 24hr h:mm or hh:mm
    $avTempSort[$i][1] = $avTempDate[3] & $avTempDate[1] & $avTempDate[2] & " " & _
            StringFormat("%02d:%02d", $avTempTime[1], $avTempTime[2])
Next
_ArraySort($avTempSort, 0, 0, 0, 1)

; Use sorted index array to create output
Global $avOutput[UBound($avInput)][UBound($avInput, 2)]
For $row = 0 To UBound($avTempSort) - 1
    For $col = 0 To UBound($avInput, 2) - 1
        $avOutput[$row][$col] = $avInput[$avTempSort[$row][0]][$col]
    Next
Next
_ArrayDisplay($avOutput, "$avOutput")

muttley


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

That's beautiful, thanks. But one favor please. I'm looking at the output loop and can't figure it out...in case I have some other need for something similar. Could you give me another example of putting the output array together, or comment up the output so I understand exactly what is happening. Prefer another way though.

Thanks.

Share this post


Link to post
Share on other sites

That's beautiful, thanks. But one favor please. I'm looking at the output loop and can't figure it out...in case I have some other need for something similar. Could you give me another example of putting the output array together, or comment up the output so I understand exactly what is happening. Prefer another way though.

Thanks.

The script creates an "index array" called $avTempSort. That array contains only the original row numbers from the input array and the reformatted date/time. The index array gets sorted on the date/time column [n][1], which moves the original index numbers in [n][0] at the same time. The new order of [n][0] indexes is then used to copy the original data from the input array to the output array.

That was only required because you didn't want to change the data in the input array. A simpler method, if you can add a new column to the input array would be to just add a new column for the re-formatted date/time and sort on that column:

#include<Array.au3>

; Create input array
Global $avInput[10][4] = [["10/20/2008", "6:47", "Something 1", "Another 1"], _
        ["10/14/2008", "8:23", "Something 2", "Another 2"], _
        ["08/21/2008", "22:46", "Something 3", "Another 3"], _
        ["08/14/2005", "11:36", "Something 4", "Another 4"], _
        ["08/14/2005", "9:40", "Something 5", "Another 5"], _
        ["12/24/2007", "2:41", "Something 6", "Another 6"], _
        ["09/18/2007", "4:11", "Something 7", "Another 7"], _
        ["05/23/2006", "6:20", "Something 8", "Another 8"], _
        ["02/25/2008", "15:50", "Something 9", "Another 9"], _
        ["02/25/2008", "7:46", "Something 10", "Another 10"]]
_ArrayDisplay($avInput, "$avInput")

; Add index column to sort on
ReDim $avInput[UBound($avInput)][UBound($avInput, 2) + 1]
$iIndexCol = UBound($avInput, 2) - 1

; Add re-formatted date/time to index column
Global $avTempDate, $avTempTime
For $i = 0 To UBound($avInput) - 1
    $avTempDate = StringSplit($avInput[$i][0], "/"); Date must be MM/DD/YYY
    $avTempTime = StringSplit($avInput[$i][1], ":"); Time must be 24hr h:mm or hh:mm
    $avInput[$i][$iIndexCol] = $avTempDate[3] & $avTempDate[1] & $avTempDate[2] & " " & _
            StringFormat("%02d:%02d", $avTempTime[1], $avTempTime[2])
Next
_ArraySort($avInput, 0, 0, 0, $iIndexCol)

_ArrayDisplay($avInput, "$avInput")

muttley


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Cool, got you, thanks. One more question...not important, but you made me wonder about it now. Is it not possible to delete a column? I know it's possible to delete rows, why not columns?

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Cool, got you, thanks. One more question...not important, but you made me wonder about it now. Is it not possible to delete a column? I know it's possible to delete rows, why not columns?

"Row" and "Column" are arbitrary labels that don't always mean the same thing.

In Spreadsheets, the first index is "rows" going down vertically, and the second index is "columns" going across the top. In Cartesian space, X always comes first for across, and then Y for vertical. _IETableWriteToArray() would create a 2D array with columns first then rows, and to avoid confusion Dale added the "transpose" parameter to reverse that as needed.

All that just to say, it's not about rows or columns, but rather dimensions or indexes of the array.

You actually can't natively delete an element in any dimension of an array in AutoIt. Crack open Array.au3 and look at the code for _ArrayDelete(). It's basically copying the data up over the element to be "deleted" and then ReDim'ing to remove the last element. You could rewrite that to delete a range of elements in the second dimension by the same process, but it's a UDF, not a native AutoIt function.

muttley

Edit: Fixed description of _ArrayDelete().

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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
Sign in to follow this  
Followers 0