LeCarre Posted June 7, 2012 Share Posted June 7, 2012 (edited) Not Newbie to coding, but have not used listview many times, and callback sorts even less First time posting code with tags, hope this is readable...FYI - I'm trying to sort time, and my solution is to convert time to ticks in a column that will eventually be out of viewand when user sorts the "00:00:00" column, i'll sort the hidden ticks column instead.Problem: Can't get it tho, why this code is producing odd sorting results in my listviewThe console shows proper evaluation of each numerical comparison.expandcollapse popupFunc LVSort($hWnd, $nItem1, $nItem2, $nColumn) Local $nSort, $val1, $val2, $nResult ; Switch the sorting direction If $nColumn = $nCurCol Then If Not $bSet Then $nSortDir = $nSortDir * - 1 $bSet = 1 EndIf Else $nSortDir = 1 EndIf $nCol = $nColumn $val1 = GetSubItemText($hWnd, $nItem1, $nColumn) $val2 = GetSubItemText($hWnd, $nItem2, $nColumn) ; If it is the 3rd colum (column starts with 0) then compare the dates If $nColumn = 2 Then $val1 = StringRight($val1, 4) & StringMid($val1, 4, 2) & StringLeft($val1, 2) $val2 = StringRight($val2, 4) & StringMid($val2, 4, 2) & StringLeft($val2, 2) EndIf if $nColumn = 2 Then ; ConsoleWrite($Val1 & " " & $Val2 & @CRLF) If Number($val1) < Number($val2) Then $nResult = -1 ; Put item2 before item1 ConsoleWrite($Val1 & " < " & $Val2 & @CRLF) Else $nResult = 1 ; Put item2 before item1 ConsoleWrite($Val1 & " > " & $Val2 & @CRLF) EndIf EndIf If $val1 < $val2 Then $nResult = -1 ; Put item2 before item1 ElseIf $val1 > $val2 Then $nResult = 1 ; Put item2 behind item1 EndIf $nResult = $nResult * $nSortDir Return $nResult EndFunc ;==>LVSortResults in my list are... um, confusing.9006100031500012256000012246100001061000100001000100100PS why is there no emoticon for coffee, or pizza? Edited June 7, 2012 by LeCarre Link to comment Share on other sites More sharing options...
LeCarre Posted June 7, 2012 Author Share Posted June 7, 2012 Nothing like 30 minutes of baking my brain on unfamiliar code to solve the problem. I patched this together from 2 sources, added my own, and the problem was that my code executed fine, and was then altered by a following piece of code. If $val1 < $val2 Then $nResult = -1 ; Put item2 before item1 ElseIf $val1 > $val2 Then $nResult = 1 ; Put item2 behind item1 EndIf which would alter any previous $nResults <--- Imagine coffee mug Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now