Sign in to follow this  
Followers 0
buymeapc

Remove an item from listview and source text file?

4 posts in this topic

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

Share this post


Link to post
Share on other sites



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

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

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