Dangerous Posted May 12, 2012 Share Posted May 12, 2012 (edited) Hi guys i have a probelm with deleting a line in a file, so here is my script: expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <WindowsConstants.au3> #include <file.au3> #include <array.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Site Blocker", 398, 351, 192, 124) $List1 = GUICtrlCreateList("", 8, 48, 161, 253) $Input1 = GUICtrlCreateInput("", 8, 16, 161, 21) $List2 = GUICtrlCreateList("", 200, 48, 161, 253) $BegLine = _LineNumsOfSearchStr(@ScriptDir & "Bock.txt", "127.0.0.1") $FileLNumber = _FileCountLines(@ScriptDir & "Bock.txt") For $i = $BegLine to $FileLNumber Step +1 $AddLine = FileReadLine(@ScriptDir & "Bock.txt", $i) GUICtrlSetData($List2, $AddLine & "|") Next $Input2 = GUICtrlCreateInput("", 200, 16, 161, 21) $Button1 = GUICtrlCreateButton("Block", 40, 312, 75, 25) $Button2 = GUICtrlCreateButton("DeBlock", 240, 312, 75, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $Button1 $SiteText = GUICtrlRead($Input1) If $SiteText <> "" Then GUICtrlSetData($List1, $SiteText & "|") $LineNumber = _FileCountLines(@ScriptDir & "Bock.txt") _FileWriteToLine(@ScriptDir & "Bock.txt", $LineNumber,"127.0.0.1" & " " & $SiteText) GUICtrlSetData($Input1, "") Else Sleep(1000) EndIf Case $Button2 $DeSite = GUICtrlRead($List2) _GUICtrlListBox_DeleteString($List2, _GUICtrlListBox_GetCaretIndex($List2)) $LineDeleteNumber = _LineNumsOfSearchStr(@ScriptDir & "Bock.txt", $DeSite, True) ;_FileWriteToLine(@ScriptDir & "Bock.txt", $LineDeleteNumber, "", 1) Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _LineNumsOfSearchStr($sFileName, $searchString, $bDeleteLine = False) Local $location, $aCurrentLineNum, $iCurrentLineNum, $sFile, $iOccur = 1, $sRes = "" If FileExists($sFileName) = 0 Then Return 1 $sFile = FileRead($sFileName) $location = StringInStr($sFile, $searchString, 0, $iOccur) ; Find the $iOccur occurrence of the "substring" If $location > 0 Then $aCurrentLineNum = StringRegExp(StringRegExpReplace($sFile, "(?s)(.{" & $location & "})(.*)$", "1"), "(?s)(v+)", 3) ;Find line number $iCurrentLineNum = UBound($aCurrentLineNum) + 1 ; Line number If $bDeleteLine Then _FileWriteToLine($sFileName, $iCurrentLineNum, "", 1) ; Remove found line from file. Else $iOccur += 1 EndIf Else EndIf Sleep(10) ;ShellExecute($sFileName) Return $iCurrentLineNum EndFunc ;==>_LineNumsOfSearchStr any idea why this won't work?: Case $Button2 $DeSite = GUICtrlRead($List2) _GUICtrlListBox_DeleteString($List2, _GUICtrlListBox_GetCaretIndex($List2)) $LineDeleteNumber = _LineNumsOfSearchStr(@ScriptDir & "Bock.txt", $DeSite, True) ;_FileWriteToLine(@ScriptDir & "Bock.txt", $LineDeleteNumber, "", 1) Thanks Edited May 12, 2012 by Dangerous Link to comment Share on other sites More sharing options...
Dangerous Posted May 13, 2012 Author Share Posted May 13, 2012 bump Link to comment Share on other sites More sharing options...
VixinG Posted May 13, 2012 Share Posted May 13, 2012 I just checked. It does work o_O Everything works fine in your script... Delete ";" at the start of the line: ;_FileWriteToLine(@ScriptDir & "Bock.txt", $LineDeleteNumber, "", 1) and everything will work... [indent=3][/indent] Link to comment Share on other sites More sharing options...
Dangerous Posted May 16, 2012 Author Share Posted May 16, 2012 I just checked. It does work o_O Everything works fine in your script... Delete ";" at the start of the line: ;_FileWriteToLine(@ScriptDir & "\Bock.txt", $LineDeleteNumber, "", 1) and everything will work... Oh... what a fool I am i could not notice I had it in comment, thanks 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