buymeapc Posted May 12, 2008 Posted May 12, 2008 I'm having an issue removing an item from a listview and my source file which happens to be a text file. It takes quite a while to find the entry in the text file and remove it from the list - around 10 - 15 seconds which is quite a while when simply removing an entry from a list. Here is my function: Func Remove() _FileReadToArray($file, $File_Array) If _GUICtrlListViewGetItemText($listview) = "" Then MsgBox(0, "Oops...", "No selection made. Nothing was removed from the list.") Return EndIf $y = MsgBox(4, "Are you sure?", "Are you sure you want to remove this item?") If $y = 6 Then For $i = 1 To $File_Array[0] If $File_Array[$i] = _GUICtrlListViewGetItemText($listview) Then _FileWriteToLine($file, $i, "", 1) ExitLoop EndIf $percent = Round(($i / $File_Array[0])*100, 0) _GUICtrlStatusBarSetText($StatusBar, "Building list, " & $percent&"% complete") GUICtrlSetData($ProgressBar1, $percent) Next _GUICtrlListViewDeleteItemsSelected($listview) EndIf GUICtrlSetData($ProgressBar1, 0) SelectionTotal() EndFunc The source file is set up like this: 192.168.30.105|00:01:02:C1:C3:CE Any help is appreciated...thanks
martin Posted May 12, 2008 Posted May 12, 2008 I'm having an issue removing an item from a listview and my source file which happens to be a text file. It takes quite a while to find the entry in the text file and remove it from the list - around 10 - 15 seconds which is quite a while when simply removing an entry from a list. Here is my function: Func Remove() _FileReadToArray($file, $File_Array) If _GUICtrlListViewGetItemText($listview) = "" Then MsgBox(0, "Oops...", "No selection made. Nothing was removed from the list.") Return EndIf $y = MsgBox(4, "Are you sure?", "Are you sure you want to remove this item?") If $y = 6 Then For $i = 1 To $File_Array[0] If $File_Array[$i] = _GUICtrlListViewGetItemText($listview) Then _FileWriteToLine($file, $i, "", 1) ExitLoop EndIf $percent = Round(($i / $File_Array[0])*100, 0) _GUICtrlStatusBarSetText($StatusBar, "Building list, " & $percent&"% complete") GUICtrlSetData($ProgressBar1, $percent) Next _GUICtrlListViewDeleteItemsSelected($listview) EndIf GUICtrlSetData($ProgressBar1, 0) SelectionTotal() EndFunc The source file is set up like this: 192.168.30.105|00:01:02:C1:C3:CE Any help is appreciated...thanksThis might be faster BUT I haven't tested it. Func Remove() Local $sText = FileRead($file) Local $search If _GUICtrlListViewGetItemText($listview) = "" Then MsgBox(0, "Oops...", "No selection made. Nothing was removed from the list.") Return EndIf $search = _GUICtrlListViewGetItemText($listview) $y = MsgBox(4, "Are you sure?", "Are you sure you want to remove this item?" & @CRLF & $search) $sText = StringRegExpReplace($sText, "\Q" & $search & "\E\r\n", "", 1) If @extended = 0 Then Return -1;failed _GUICtrlListViewDeleteItemsSelected($listview) ;I'm assuming $file is the full path to the file and not a handle $Local $hF = FileOpen($file, 2) FileWrite($hF, $sText) FileClose($hF) SelectionTotal() EndFunc ;==>Remove Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
buymeapc Posted May 12, 2008 Author Posted May 12, 2008 Thank you! That is WAY faster. It now takes a total of like 1 second - huge difference. Here's the code I used: Func Remove() Local $sText = FileRead($file) Local $search If _GUICtrlListViewGetItemText($listview) = "" Then MsgBox(0, "Oops...", "No selection made. Nothing was removed from the list.") Return EndIf $search = _GUICtrlListViewGetItemText($listview) $y = MsgBox(4, "Are you sure?", "Are you sure you want to remove this item?" & @CRLF & $search) If $y = 6 Then $sText = StringRegExpReplace($sText, "\Q" & $search & "\E\r\n", "", 1) If @extended = 0 Then Return -1;failed _GUICtrlListViewDeleteItemsSelected($listview) Local $hF = FileOpen($file, 2) FileWrite($hF, $sText) FileClose($hF) EndIf SelectionTotal() EndFunc ;==>Remove I'm now going to (try to) add a way for multiple selections to be removed this way as well...wish me luck! lol Thanks again
martin Posted May 12, 2008 Posted May 12, 2008 Thank you! That is WAY faster. It now takes a total of like 1 second - huge difference. Here's the code I used: Func Remove() Local $sText = FileRead($file) Local $search If _GUICtrlListViewGetItemText($listview) = "" Then MsgBox(0, "Oops...", "No selection made. Nothing was removed from the list.") Return EndIf $search = _GUICtrlListViewGetItemText($listview) $y = MsgBox(4, "Are you sure?", "Are you sure you want to remove this item?" & @CRLF & $search) If $y = 6 Then $sText = StringRegExpReplace($sText, "\Q" & $search & "\E\r\n", "", 1) If @extended = 0 Then Return -1;failed _GUICtrlListViewDeleteItemsSelected($listview) Local $hF = FileOpen($file, 2) FileWrite($hF, $sText) FileClose($hF) EndIf SelectionTotal() EndFunc;==>Remove I'm now going to (try to) add a way for multiple selections to be removed this way as well...wish me luck! lol Thanks again That's ok, glad it worked. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
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