Sign in to follow this  
Followers 0
ttleser

Help with GUICtrlListViewSort

5 posts in this topic

I've got a script that scans 20 computers for versions of programs and puts the info into a listview. The listview will show 2 columns, the left one for the computers and the right one is for the output of the version. I'm having a problem with the sorting. I used GUICtrlListViewSort so that you can click on either the computer column or the output column. It'll sort the output perfectly, but the computer column doesn't sort properly. The computer column will show upon the initial scan:

PC 1

PC 2

PC 3

PC 4

PC 5

PC 6

PC 7

PC 8

PC 9

PC 10

PC 11

etc..

But if you click on the computer column to sort by that it'll look like:

PC 1

PC 10

PC 11

etc..

I'd like it to look like:

PC 1

PC 2

etc...

Any thoughts?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

ah you are right :) , i just tried an example with your values (PC 1 - PC 12) and it comes :

PC 1

PC 10

PC 11

PC 12

PC 2

PC 3

etc.

too bad.... but maybe you could find a workaround

Edited by Gif

Share this post


Link to post
Share on other sites

In your GUICtrlRegisterListViewSort - LVSort() routine use Number() function for desired substring of itemtext.

"PC 9", "PC 10" are treated as texts with differrent length, so if first three chars are always the same then sort by:

Number(StringMid($val,4))

Share this post


Link to post
Share on other sites

Thanks for the post Zedna, but I'm not sure how to implement that. Here's my code (please keep in mind I'm new to programming, so it may have unneeded code for it may be poorly done):

#include <GuiConstants.au3>
#include <GuiListView.au3>
#include <file.au3>

Dim $aArray

$File = "Programs.txt"
_FileReadToArray ($File, $aArray )

GUICreate("Version Finder", 500, 440)

;New Combo Box - Uses an array to have the lines in the text file read into.
;             - For/Next statement writes the data into the Array.
GUICtrlCreateLabel ("Game", 10, 15)
$combo=GUICtrlCreateCombo ("", 10,30,175,100); create first item
For $x = 1 to $aArray[0]
    GUICtrlSetData(-1, $aArray[$x])
Next

;Old Combo box
;GUICtrlCreateLabel ("Game", 10, 15)
;$combo=GUICtrlCreateCombo ("", 10,30,175,100); create first item
;GUICtrlSetData(-1,$game1&"|"&$game2&"|"&$game3&"|"&$game4&"|"&$game5&"|"&$game6&"|"&$game7&"|"&$game8&"|"&$game9&"|"&$game10&"|"&$game11&"|"&$game12&"|"&$game13&"|"&$game14&"|"&$game15&"|"&$game16&"|"&$game17&"|"&$game18&"|"&$game19&"|"&$game20&"|"&$game21&"|"&$game22&"|"&$game23&"|"&$game24&"|"&$game25&"|"&$game26&"|"&$game27&"|"&$game28&"|"&$game29&"|"&$game30&"|"&$game31&"|"&$game32&"|"&$game33&"|"&$game34,$game1)


;Output listview
;GUICtrlCreateLabel ("Version Output", 265, 15)
;$listView = GUICtrlCreateListView("Computer|Version                       ", 210, 30, 195, 310)
GUICtrlCreateLabel ("Version Output", 10, 95)
$listView = GUICtrlCreateListView("Computer|Version                    ", 10, 110, 195, 310)
$button_scan = GUICtrlCreateButton('&Scan', 25, 65, 60, 23,0x0001)
$button_exit = GUICtrlCreateButton('E&xit', 115, 65, 60, 23)
Dim $B_DESCENDING[_GUICtrlListViewGetSubItemsCount ($listview) ]



GUISetState ()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $button_exit
            Exit    
        Case $msg = $button_scan
            If GUICtrlRead($combo) = "FarCry" Then FarCry()
            If GUICtrlRead($combo) = "Halo" Then Halo()
            If GUICtrlRead($combo) = "NeverWinter Nights" Then NeverWinterNights()
            If GUICtrlRead($combo) = "NeverWinter Nights CEP" Then NeverWinterNightsCEP()
            If GUICtrlRead($combo) = "NeverWinter Nights 2" Then NeverWinterNights2()
            If GUICtrlRead($combo) = "Battlefield 2" Then Battlefield2()
            If GUICtrlRead($combo) = "Warcraft III" Then WarcraftIII()
            If GUICtrlRead($combo) = "Lord of the Rings  BFME" Then LOTRBFME()
            If GUICtrlRead($combo) = "Call of Duty" Then CallOfDuty()
            If GUICtrlRead($combo) = "Company of Heroes" Then CompanyofHeroes()
            If GUICtrlRead($combo) = "World Of Warcraft" Then WorldOfWarcraft()
            If GUICtrlRead($combo) = "City Of Heroes" Then CityOfHeroes()
            If GUICtrlRead($combo) = "Battlefield 2142" Then Battlefield2142()
        Case $msg = $listview
           ; sort the list by the column header clicked on
            Number(StringMid($listview,4))
            _GUICtrlListViewSort($listview, $B_DESCENDING, GUICtrlGetState($listview))
    EndSelect
WEnd

Func Battlefield2()
    $IP = 1
    _GUICtrlListViewDeleteAllItems($listView)
    Do
    $pingpc = Ping("192.168.100."&$IP, 250)
    If $pingpc <> 0 Then
        $line = FileReadLine("\\192.168.100."&$IP&"\c$\Games\EA GAMES\Battlefield 2\Support\readme.txt",2)
        If @error = -1 Then ExitLoop
        $output = StringRight($line, 4)
            Else
        $output = "Offline"
    EndIf
    GUICtrlCreateListViewItem("PC " & $IP & "|" &$output, $listView)
    $IP = $IP + 1
    Until $IP = 21
EndFunc

Func Battlefield2142()
    $IP = 1
    _GUICtrlListViewDeleteAllItems($listView)
    Do
        $pingpc = ping ("192.168.100."&$IP,50)
            If $pingpc <> 0 then 
                $output = RegRead("\\192.168.100."&$IP&"\HKEY_LOCAL_MACHINE\SOFTWARE\Electronic Arts\EA Games\Battlefield 2142", "Version")
            Else
                $output = "Offline"
            EndIf
            GUICtrlCreateListViewItem("PC " & $IP & "|" &$output, $listView)
            $IP = $IP + 1
    Until $IP = 21  
EndFunc

Func CallOfDuty()
    $IP = 1
    _GUICtrlListViewDeleteAllItems($listView)
    Do
        $pingpc = ping ("192.168.100."&$IP,50)
            If $pingpc <> 0 then 
                $output = RegRead("\\192.168.100."&$IP&"\HKEY_LOCAL_MACHINE\SOFTWARE\Activision\Call of Duty", "Version")
            Else
                $output = "Offline"
            EndIf
            GUICtrlCreateListViewItem("PC " & $IP & "|" &$output, $listView)
            $IP = $IP + 1
    Until $IP = 21  
EndFunc

Func CallOfDutyUO()
    $IP = 1
    _GUICtrlListViewDeleteAllItems($listView)
    Do
        $pingpc = ping ("192.168.100."&$IP,50)
            If $pingpc <> 0 then 
                $output = RegRead("\\192.168.100."&$IP&"\HKEY_LOCAL_MACHINE\SOFTWARE\Activision\Call of Duty United Offensive", "Version")
            Else
                $output = "Offline"
            EndIf
            GUICtrlCreateListViewItem("PC " & $IP & "|" &$output, $listView)
            $IP = $IP + 1
    Until $IP = 21  
EndFunc

Func CallOfDuty2()
    $IP = 1
    _GUICtrlListViewDeleteAllItems($listView)
    Do
        $pingpc = ping ("192.168.100."&$IP,50)
            If $pingpc <> 0 then 
                $output = RegRead("\\192.168.100."&$IP&"\HKEY_LOCAL_MACHINE\SOFTWARE\Activision\Call of Duty 2", "Version")
            Else
                $output = "Offline"
            EndIf
            GUICtrlCreateListViewItem("PC " & $IP & "|" &$output, $listView)
            $IP = $IP + 1
    Until $IP = 21  
EndFunc

Func CityOfHeroes()
    $IP = 1
    _GUICtrlListViewDeleteAllItems($listView)
    Do
    $pingpc = Ping("192.168.100."&$IP, 250)
    If $pingpc <> 0 Then
        $line = FileReadLine("\\192.168.100."&$IP&"\c$\Games\City Of Heroes\Coh.checksum",2)
        If @error = -1 Then ExitLoop
        $temp_output = StringTrimLeft ($line, 6)
        $output = StringReplace($temp_output,'"', "")
    ;$temp_output = StringRight($line, 15)
    ;$output = StringTrimRight($temp_output, 1)
            Else
        $output = "Offline"
    EndIf
    GUICtrlCreateListViewItem("PC " & $IP & "|" &$output, $listView)
    $IP = $IP + 1
    Until $IP = 21
EndFunc

Func CompanyofHeroes()
    $IP = 1
    _GUICtrlListViewDeleteAllItems($listView)
    Do
        $pingpc = ping ("192.168.100."&$IP,50)
            If $pingpc <> 0 then 
                $output = RegRead("\\192.168.100."&$IP&"\HKEY_LOCAL_MACHINE\SOFTWARE\THQ\Company of Heroes", "Version")
            Else
                $output = "Offline"
            EndIf
            GUICtrlCreateListViewItem("PC " & $IP & "|" &$output, $listView)
            $IP = $IP + 1
    Until $IP = 21  
EndFunc

Func FarCry()
    $IP = 1
    _GUICtrlListViewDeleteAllItems($listView)
    Do
    $pingpc = Ping("192.168.100."&$IP, 250)
    If $pingpc <> 0 Then
        $search = FileFindFirstFile("\\192.168.100."&$IP&"\c$\games\Ubisoft\Crytek\Far Cry\Support\Readme.txt")
        $filename = FileFindNextFile($search)
        $line = FileReadLine("\\192.168.100."&$IP&"\c$\games\Ubisoft\Crytek\Far Cry\Support\Readme.txt",2)
        If @error = -1 Then ExitLoop
        $output = StringRight($line, 4)
    Else
        $output = "Offline"
    EndIf
    GUICtrlCreateListViewItem("PC " & $IP & "|" &$output, $listView)
    $IP = $IP + 1
    Until $IP = 21
EndFunc

Func Halo()
    $IP = 1
    _GUICtrlListViewDeleteAllItems($listView)
    Do
        $pingpc = ping ("192.168.100."&$IP,50)
            If $pingpc <> 0 then 
                $output = RegRead("\\192.168.100."&$IP&"\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft Games\Halo", "Version")
;               msgbox(0,"test",$IP)
            Else
                $output = "Offline"
            EndIf
            GUICtrlCreateListViewItem("PC " & $IP & "|" &$output, $listView)
            $IP = $IP + 1
    Until $IP = 21  
EndFunc

Func LOTRBFME()
    $IP = 1
    _GUICtrlListViewDeleteAllItems($listView)
    Do
    $pingpc = Ping("192.168.100."&$IP, 250)
    If $pingpc <> 0 Then
        $file = FileOpen("\\192.168.100."&$IP&"\c$\Games\EA GAMES\The Battle for Middle-earth (tm)\patch.doc", 0)
        $line = FileReadLine($file,6)
        If @error = -1 Then ExitLoop
        $output = StringMid($line, 9, 30)
    Else
        $output = "Offline"
    EndIf
    GUICtrlCreateListViewItem("PC " & $IP & "|" &$output, $listView)
    $IP = $IP + 1
    Until $IP = 21
EndFunc

Func NeverWinterNights()
    $IP = 1
    _GUICtrlListViewDeleteAllItems($listView)
    Do
    $pingpc = Ping("192.168.100."&$IP, 250)
    If $pingpc <> 0 Then
        $search = FileFindFirstFile("\\192.168.100."&$IP&"\c$\Games\NeverwinterNights\NWN\NWNv*.txt")
        $filename = FileFindNextFile($search)
;       $file = FileOpen($filename, 0)
;       $file = FileOpen("\\192.168.100."&$IP&"\c$\Games\NeverwinterNights\NWN\NWNv168.txt", 0)
;       msgbox(0,"test",$file)
;       $line = FileReadLine($file)
        If @error = -1 Then ExitLoop
        $string1 = StringRight($filename, 7)
        $string2 = StringLeft($string1,1)
        $string3 = StringMid($string1,2,2)
        $output = $string2&"."&$string3
    Else
        $output = "Offline"
    EndIf
    GUICtrlCreateListViewItem("PC " & $IP & "|" &$output, $listView)
    $IP = $IP + 1
    Until $IP = 21
EndFunc

Func NeverWinterNightsCEP()
    $IP = 1
    _GUICtrlListViewDeleteAllItems($listView)
    Do
    $pingpc = Ping("192.168.100."&$IP, 250)
    If $pingpc <> 0 Then
        If FileExists("\\192.168.100."&$IP&"\c$\Games\NeverwinterNights\NWN\cep\CEPv2 Docs.pdf") Then
            $output = "2.00"
        Else
            $line = FileReadLine("\\192.168.100."&$IP&"\c$\Games\NeverwinterNights\NWN\cep\readme.txt",1)
            $output = StringRight($line, 4)
        EndIf
    Else
        $output = "Offline"
    EndIf
    GUICtrlCreateListViewItem("PC " & $IP & "|" &$output, $listView)
    $IP = $IP + 1
    Until $IP = 21
EndFunc

Func NeverWinterNights2()
    $IP = 1
    _GUICtrlListViewDeleteAllItems($listView)
    Do
    $pingpc = Ping("192.168.100."&$IP, 250)
    If $pingpc <> 0 Then
        Local $highest, $first = FileFindFirstFile('\\192.168.100.'&$IP&'\c$\Games\Atari\Neverwinter Nights 2\patch_notes*.rtf')
        While 1
            $found = FileFindNextFile($first)
            If @error Then ExitLoop
                $ver = Number(StringReplace(StringReplace($found, 'patch_notes_v', ''), '.rtf', ''))
                    If $ver > $highest Then
                        $highest = $ver
                        $file = $found
                    EndIf
        WEnd
        $string2 = StringLeft($highest,1)
        $string3 = StringMid($highest,2,2)
        $output = $string2&"."&$string3
    Else
        $output = "Offline"
    EndIf
    GUICtrlCreateListViewItem("PC " & $IP & "|" &$output, $listView)
    
; Reset variables as they were retaining previous values.
    $ver = ""
    $highest = ""
    $IP = $IP + 1
    Until $IP = 21
EndFunc

Func WarcraftIII()
    $IP = 1
    _GUICtrlListViewDeleteAllItems($listView)
    Do
    $pingpc = Ping("192.168.100."&$IP, 250)
    If $pingpc <> 0 Then
        $file = FileOpen("\\192.168.100."&$IP&"\c$\Games\Warcraft III\patch.txt", 0)
        $line = FileReadLine($file,6)
        If @error = -1 Then ExitLoop
        $output = StringMid($line, 7, 6)
    Else
        $output = "Offline"
    EndIf
    GUICtrlCreateListViewItem("PC " & $IP & "|" &$output, $listView)
    $IP = $IP + 1
    Until $IP = 21
EndFunc

Func WorldOfWarcraft()
    $IP = 1
    _GUICtrlListViewDeleteAllItems($listView)
    Do
    $pingpc = Ping("192.168.100."&$IP, 250)
    If $pingpc <> 0 Then
        $line = FileReadLine("\\192.168.100."&$IP&"\c$\Games\World of Warcraft\patch.txt",2)
        If @error = -1 Then ExitLoop
        $output = StringRight($line, 5)
            Else
        $output = "Offline"
    EndIf
    GUICtrlCreateListViewItem("PC " & $IP & "|" &$output, $listView)
    $IP = $IP + 1
    Until $IP = 21
EndFunc

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