Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 11/18/2012 in all areas

  1. A better example that sorts a list view by the column that is clicked on that column's header. The column sorts acsending and decending with each click. #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #include <Array.au3> #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <GuiImageList.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) ; 1 = enable. Opt("GUICloseOnESC", 1) ; 1 = Send the $GUI_EVENT_CLOSE message when ESC is pressed (default). Opt('MustDeclareVars', 1) Global $hListView _Example1() While 1 Sleep(100) WEnd Func _Example1() ;Local $hImage Local $iExWindowStyle = BitOR($WS_EX_DLGMODALFRAME, $WS_EX_CLIENTEDGE) Local $iExListViewStyle = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER) GUICreate("ListView Sort", 300, 400) GUISetOnEvent($GUI_EVENT_CLOSE, "CloseGUI") $hListView = GUICtrlCreateListView("Column1|Column2|Column3|Col4", 10, 10, 280, 380, -1, $iExWindowStyle) _GUICtrlListView_SetExtendedListViewStyle($hListView, $iExListViewStyle) GUICtrlSetOnEvent($hListView, "sort") _AddRow($hListView, "10/20/2001|2|7|10/14/2012") _AddRow($hListView, "12/15/2000|1|8|5/22/2012") _AddRow($hListView, "04/05/2004|----|----|----") _AddRow($hListView, "1/22/2004|4|6|1/4/2012") _AddRow($hListView, "11/05/2005|5|3|10/12/2012") _AddRow($hListView, "8/15/2004|6|2|10/10/2010") _AddRow($hListView, "10/05/2008|7||11/11/2011") _AddRow($hListView, "11/05/2012|8|4|05/15/2005") _AddRow($hListView, "12/05/2012|9|5|1/21/2004") GUISetState() _GUICtrlListView_RegisterSortCallBack($hListView) EndFunc ;==>_Example1 Func sort() Local $iCol = GUICtrlGetState($hListView) Local $iRowCount = _GUICtrlListView_GetItemCount(ControlGetHandle("ListView Sort", "", $hListView)) ; ----- If the column clicked contains date formated "MM/DD/YYYY" in the first, middle, or last ; row, then convert to date format "YYYY/MM/DD" ---- If StringRegExp(_GUICtrlListView_GetItemText($hListView, 0, $iCol), "(d{1,2})[/.-](d{1,2})[/.-](d{4})") Or _ StringRegExp(_GUICtrlListView_GetItemText($hListView, $iRowCount - 1, $iCol), "(d{1,2})[/.-](d{1,2})[/.-](d{4})") Or _ StringRegExp(_GUICtrlListView_GetItemText($hListView, Int($iRowCount / 2), $iCol), "(d{1,2})[/.-](d{1,2})[/.-](d{4})") Then Local $aItem2D[$iRowCount][2], $aTemp For $i = 0 To $iRowCount - 1 $aItem2D[$i][0] = _GUICtrlListView_GetItemText($hListView, $i, $iCol) If StringRegExp($aItem2D[$i][0], "(d{1,2})[/.-](d{1,2})[/.-](d{4})") Then $aTemp = StringRegExp($aItem2D[$i][0], "(d+)", 3) $aItem2D[$i][1] = StringFormat("%4d/%02d/%02d", $aTemp[2], $aTemp[0], $aTemp[1]) _GUICtrlListView_SetItem($hListView, $aItem2D[$i][1], $i, $iCol) Else $aItem2D[$i][1] = $aItem2D[$i][0] _GUICtrlListView_SetItem($hListView, $aItem2D[$i][1], $i, $iCol) EndIf ;ConsoleWrite($aItem2D[$i][0] & " " & $aItem2D[$i][1] & @LF) Next ;ConsoleWrite(@LF) ; -------- Sort all columns ---------- _GUICtrlListView_SortItems($hListView, $iCol) ; -------- Convert date format "YYYY/MM/DD" back to the original format -------- For $i = 0 To $iRowCount - 1 For $j = 0 To $iRowCount - 1 If StringCompare(_GUICtrlListView_GetItemText($hListView, $i, $iCol), $aItem2D[$j][1]) = 0 Then _GUICtrlListView_SetItem($hListView, $aItem2D[$j][0], $i, $iCol) ExitLoop 1 EndIf Next Next Else _GUICtrlListView_SortItems($hListView, $iCol) EndIf EndFunc ;==>sort Func _AddRow($hWnd, $sItem) Local $aItem = StringSplit($sItem, "|"), $iColWidth Local $iIndex = _GUICtrlListView_AddItem($hWnd, $aItem[1], -1, _GUICtrlListView_GetItemCount($hWnd)) _GUICtrlListView_SetColumnWidth($hWnd, 0, $LVSCW_AUTOSIZE_USEHEADER) For $x = 2 To $aItem[0] _GUICtrlListView_AddSubItem($hWnd, $iIndex, $aItem[$x], $x - 1) _GUICtrlListView_SetColumnWidth($hWnd, $x - 1, $LVSCW_AUTOSIZE) $iColWidth = _GUICtrlListView_GetColumnWidth($hWnd, $x - 1) _GUICtrlListView_SetColumnWidth($hWnd, $x - 1, $LVSCW_AUTOSIZE_USEHEADER) If $iColWidth > _GUICtrlListView_GetColumnWidth($hWnd, $x - 1) Then _GUICtrlListView_SetColumnWidth($hWnd, $x - 1, $LVSCW_AUTOSIZE) EndIf Next EndFunc ;==>_AddRow Func CloseGUI() _GUICtrlListView_UnRegisterSortCallBack($hListView) GUIDelete() Exit EndFunc ;==>CloseGUI
    1 point
  2. I very rarely add comments, opting for very descriptive function names and variables. Yes, the use comments dog snaps around my ankles all the time, but I just ignore it. I have found that it's not big and not clever, but I just don't like yapping little dogs. For the record, I still advise people to use comments, and think it's wise to do so.
    1 point
  3. BrewManNH

    HH:MM:SS Timer Tooltip

    Don't use the full featured editor when pasting code into the code tags, switch to the basic editor (it's the button on the top left of the edit box), then paste the code. You can switch back after the code has been pasted. But if you edit the post, the formatting gets messed up again even when using the basic edit mode. Just an FYI
    1 point
  4. jchd

    <number> + <bool> = <type?>

    Do you mean "Double True"? [Just kidding] I second that. Note that it's precisely what is said (albeit implied) in the help file under Language Reference > Datatypes > Notice that the values shown are indeed integers. Double values would be (resp.) 1. 0. 101. or more clearly 1.0 0.0 and 101.0 In this case it isn't promotion, it's demotion! Not all (exact) integers can be represented exactly as double. Even then, a double value of 1.0 is in fact an abstract representation of an interval of reals whose mapping in the double format gets to 1.0 but there is no such ambiguity with integers. That's also highly questionable. The order of operands for the addition and multiplication should never impact the result. This is violating a fundamental property of these operations: commutativity. Let alone associativity and distributivity... I can understand the reasonning behind the scene: since a double is able to represent a broader range of values, let's keep immune to integer overflow by mapping the operation to doubles. This way saves a few cycles but leads to surprising results mentionned in this thread. That's done at the expense of accuracy. I would favor an implementation where conversion to double is only done when integral overflow is experienced. That means a few cycles spent for each operation but that would give consistent results and a way for the programmer to notice that an overflow occured (when such things can actually happen and they have significance) by testing VarGetType.
    1 point
  5. I wish my nurse felt the same way, every time I need by nappy changing she's out shopping somewhere.
    1 point
  6. See the "Automate input type=file" link in my sig. Dale
    1 point
×
×
  • Create New...