buymeapc Posted December 6, 2007 Share Posted December 6, 2007 I'm currently populating a listview using a Do While loop and it takes around 10 seconds to populate the list. Is there a better alternative? Thanks Func StartUp() Local $clicks = 0, $info _GUICtrlListViewSetColumnWidth ($listview, 0, 93) Dim $B_DESCENDING[_GUICtrlListViewGetSubItemsCount ($listview) ] $num = 1 Global $strMACAddress If FileExists($file) = 0 Then FileWrite($file, "") $msg = GUIGetMsg() Do $line = FileReadLine($file, $num) If $line <> "" Then GUICtrlCreateListViewItem($line, $listview) $num = $num + 1 $percent = Round(($num / _FileCountLines($file))*100, 0) _GUICtrlStatusBarSetText($StatusBar, "Building list, " & $percent&"% complete") GUICtrlSetData($ProgressBar1, $percent) Until $line = "" _GUICtrlListViewSort($listview, $B_DESCENDING, 0) GUISetState(@SW_ENABLE, $main) GUICtrlSetState($input, $GUI_FOCUS) GUICtrlSetData($ProgressBar1, 0) SelectionTotal() EndFunc Link to comment Share on other sites More sharing options...
DjDeep00 Posted December 6, 2007 Share Posted December 6, 2007 @buymeapc....I wouldnt use a do loop for this....try using the following... _FileReadToArray($file,$File_Array) For $x=1 to $File_Array[0] ;Create your listviewitems ;Update your progressbar Next Link to comment Share on other sites More sharing options...
buymeapc Posted December 6, 2007 Author Share Posted December 6, 2007 thanks, that cut the load time in half. Now, I have to figure out if I can cut the sort time...I may be asking too much, though. Link to comment Share on other sites More sharing options...
DjDeep00 Posted December 6, 2007 Share Posted December 6, 2007 If you mean sorting the listview results...then yes sure you can...just search the forum for listview and sort. There are many UDFs out there but I believe gafrost's udf is pretty fast.... Link to comment Share on other sites More sharing options...
weaponx Posted December 6, 2007 Share Posted December 6, 2007 Personally, I would use _FileReadToArray() to read the info in, then use _ArraySort(), then populate the listview. This would eliminate the need to use the ListView sort. Link to comment Share on other sites More sharing options...
randallc Posted December 6, 2007 Share Posted December 6, 2007 Hi, 1. I agree with WeaponX 2. Take "_FileCountLines" out of any loop as it reads the whole file each time (assign to var) 3. If only one column, consider "ListBox" instead of listview; 3a then you can do fileread without array, replace "@crlf" with "|" separator, add to LB in one command, no loop, and automatically sorts 4. I f you use LV and ArraySort is still slow, quickest sort on 1D array is via jscript and scripting object (10x) Let me know.. Best, Randall ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW Link to comment Share on other sites More sharing options...
buymeapc Posted December 6, 2007 Author Share Posted December 6, 2007 Oh wow, that is so much better!! I commented out the status bar lines and what a difference! Thanks guys!....Here's the code I used: Func StartUp() GUISetState(@SW_DISABLE, $main) Local $File_Array, $num = 1 _GUICtrlListViewSetColumnWidth ($listview, 0, 93) Dim $B_DESCENDING[_GUICtrlListViewGetSubItemsCount ($listview) ] If FileExists($file) = 0 Then FileWrite($file, "") _FileReadToArray($file, $File_Array) _ArraySort($File_Array, 0, 1) $msg = GUIGetMsg() For $x = 1 To $File_Array[0] If $File_Array[$x] <> "" Then GUICtrlCreateListViewItem($File_Array[$x], $listview) ;$num = $num + 1 ;$percent = Round(($num / _FileCountLines($file))*100, 0) ;_GUICtrlStatusBarSetText($StatusBar, "Building list, " & $percent&"% complete") ;GUICtrlSetData($ProgressBar1, $percent) Next ;_GUICtrlListViewSort($listview, $B_DESCENDING, 0) GUISetState(@SW_ENABLE, $main) GUICtrlSetState($input, $GUI_FOCUS) ;GUICtrlSetData($ProgressBar1, 0) SelectionTotal() GUISetState(@SW_ENABLE, $main) EndFunc 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