Jump to content

List Sort Problem


pollardd
 Share

Recommended Posts

Hi Everyone,

I'm trying to sort a listview. I'm relative new to Autoit and very new to the gui stuff. (looks great however)

I have managed to load a list out of a database with about 850 entries and I'd like to be able sort them by column.

I have followed the example in the help named _GUICntrlListViewSort.au3

I receive the following error at run time.

>Running:(3.2.2.0):C:\Program Files\AutoIt3\autoit3.exe "C:\Data\JobMaster\jobmaster.au3"

C:\PROGRA~1\AutoIt3\Include\GuiListView.au3 (1744) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

$b_desc = $v_descending[$i_sortcol]

$b_desc = ^ ERROR

+>21:32:38 AutoIT3.exe ended.rc:0

+>21:32:39 AutoIt3Wrapper Finished

>Exit code: 0 Time: 10.326

Here is my code incase I have done something silly. :whistle:

I have seen other people talk about sorting thousands of records and the only issue has been speed so it may well be something silly I have missed.

Thanks in advance David.

#include <GUIConstants.au3>
#include <File.au3>
#include <GuiListView.au3>

;Opt('MustDeclareVars', 1)

DIM $sLogPath
$sLogPath=".\LobMaster.log"

DIM $DebugLevel
$DebugLevel=9   ;Values 1=low 9=high

Dim $ReturnCode

Dim $CursorBusy
Dim $StoreCursor
$CursorBusy=0

Dim $SQL_SP_ADDRESS
$SQL_SP_ADDRESS="SELECT OwnersCorporation.sPlanNumber, StreetAddress.lStreetNumber, StreetAddress.sStreetNumberSuffix, StreetAddress.sStreet, StreetAddress.sTown, StreetAddress.sPostcode FROM OwnersCorporation INNER JOIN StreetAddress ON OwnersCorporation.lMainAddressID = StreetAddress.lStreetAddressID AND OwnersCorporation.lOwnersCorporationID = StreetAddress.lOwnersCorporationID WHERE (OwnersCorporation.bManaged = 'Y') ORDER BY OwnersCorporation.sPlanNumber"

#Region ### START Koda GUI section ### Form=c:\program files\autoit3\koda\forms\aform1.kxf
$Form1_1 = GUICreate("Job Master", 633, 447, 190, 111,0x04CF0000, 0x00000110)
$ButtonCancel = GUICtrlCreateButton("Cancel", 480, 393, 121, 39, 0)
$ButtonOK = GUICtrlCreateButton("OK", 341, 394, 121, 39, 0)

;Create the List
$ListStrataPlan = GUICtrlCreateListView ("Strata Plan |Number | |Street |Suburb |Postcode",10,10,600,375);,$LVS_SORTDESCENDING)
;$listview = GUICtrlCreateListView("col1|col2|col3", 40, 30, 310, 149)
GUICtrlSendMsg($ListStrataPlan, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES)
GUICtrlSendMsg($ListStrataPlan, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT)

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

;Used for sorting the list
Dim $B_DESCENDING[_GUICtrlListViewGetSubItemsCount ($ListStrataPlan) ]

;Initialise Window
HotkeySet("{Esc}", "AbortApplication")
LoadStrataPlans()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        
        Case $ButtonCancel
            Exit
        
        Case $ButtonOK
            if $DebugLevel >= 1 then _FileWriteLog ( $sLogPath, "Processing OK button" )
        Case $nMsg = $ListStrataPlan
            ; sort the list by the column header clicked on
            _GUICtrlListViewSort($ListStrataPlan, $B_DESCENDING, GUICtrlGetState($ListStrataPlan))
    EndSwitch
WEnd

Func LoadStrataPlans()
            $objConn = ObjCreate("ADODB.Connection")
            $objConn.Open("Provider='sqloledb';Data Source='DESKTOP\SQLEXPRESS';Initial Catalog='Strata';User ID='sa';Password='removed';")
            $rsStrataDetails = $objConn.Execute($SQL_SP_ADDRESS)
            With $rsStrataDetails
                While Not .EOF
                    $ReturnCode=GUICtrlCreateListViewItem(.Fields("sPlanNumber").Value & "|" & .Fields("lStreetNumber").Value & "|" & .Fields("sStreetNumberSuffix").Value & "|" & .Fields("sStreet").Value & "|" & .Fields("sTown").Value & "|" & .Fields("sPostcode").Value, $ListStrataPlan)
                    if $DebugLevel >=9 then _FileWriteLog ( $sLogPath, "<LoadStrataPlans> Create List Data Item SP=" &.Fields("sPlanNumber").Value & " ReturnCode=" & $ReturnCode )
                    .MoveNext
                WEnd
                .Close
            EndWith
            $objConn.Close
EndFunc

Func AbortApplication()
    if $DebugLevel >=1 then _FileWriteLog ( $sLogPath, "<AbortApplication> Aborted via escape key ")
    Exit    
EndFunc
Link to comment
Share on other sites

Hi Everyone,

I'm trying to sort a listview. I'm relative new to Autoit and very new to the gui stuff. (looks great however)

I have managed to load a list out of a database with about 850 entries and I'd like to be able sort them by column.

I have followed the example in the help named _GUICntrlListViewSort.au3

I receive the following error at run time.

>Running:(3.2.2.0):C:\Program Files\AutoIt3\autoit3.exe "C:\Data\JobMaster\jobmaster.au3"

C:\PROGRA~1\AutoIt3\Include\GuiListView.au3 (1744) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

$b_desc = $v_descending[$i_sortcol]

$b_desc = ^ ERROR

+>21:32:38 AutoIT3.exe ended.rc:0

+>21:32:39 AutoIt3Wrapper Finished

>Exit code: 0 Time: 10.326

Here is my code incase I have done something silly. :whistle:

I have seen other people talk about sorting thousands of records and the only issue has been speed so it may well be something silly I have missed.

Thanks in advance David.

It's hard to try without SQL Express server, but maybe you consider to get your data already sorted from your SQL server by using ORDER BY clausule. That will also do with your speed problem.

Have a nice day

Link to comment
Share on other sites

It's hard to try without SQL Express server, but maybe you consider to get your data already sorted from your SQL server by using ORDER BY clausule. That will also do with your speed problem.

Have a nice day

Hi Libor,

Thanks for the reply. Sorry, it was a bit rude of me to post the whole program with out cutting it down. I was just hoping someone would say "There it is"

I do have an ORDER BY in there but it would be nice to sort by a different column or in reverse order by clicking on the colum heading. To simplify the problem I have cut my example down to bare bones and hardcoded the data so it is easy to test.

I have compared it to the example in the help and for the life of me I can't spot what I'm doing wrong.

Here is the way it looks now.

If I comment out the one line that starts with "_GUICtrlListViewSort" the list loads and displays ok.

David

#include <GUIConstants.au3>
#include <GuiListView.au3>


#Region ### START Koda GUI section ### Form=c:\program files\autoit3\koda\forms\aform1.kxf
$Form1_1 = GUICreate("Job Master", 633, 447, 190, 111,0x04CF0000, 0x00000110)
$ButtonCancel = GUICtrlCreateButton("Cancel", 480, 393, 121, 39, 0)
$ButtonOK = GUICtrlCreateButton("OK", 341, 394, 121, 39, 0)

;Create the List
$ListStrataPlan = GUICtrlCreateListView ("COL1 |COL2 |COL3 |COL4 |COL5",10,10,600,375);,$LVS_SORTDESCENDING)
GUICtrlSendMsg($ListStrataPlan, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES)
GUICtrlSendMsg($ListStrataPlan, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT)

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Dim $B_DESCENDING[_GUICtrlListViewGetSubItemsCount ($ListStrataPlan) ]

For $Y = 1 To 6
    $ReturnCode=GUICtrlCreateListViewItem($Y & "1 |" &$Y & "2 |" &$Y & "3 |" &$Y & "4 |" & $Y & "5", $ListStrataPlan)
Next

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        
        Case $ButtonCancel
            Exit
        
        Case $ButtonOK

        Case $nMsg = $ListStrataPlan
            ; sort the list by the column header clicked on
            _GUICtrlListViewSort($ListStrataPlan, $B_DESCENDING, GUICtrlGetState($ListStrataPlan))
    EndSwitch
WEnd
Link to comment
Share on other sites

That Fixed it.

I see there must be two different ways of doing that while loop and I had a mixture of them both.

Thanks for point it out, I new it must have been stareing me in the face.

(sorry about the empty post)

David

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