Prab Posted September 25, 2008 Share Posted September 25, 2008 (edited) Hi, I am having trouble with the following. expandcollapse popup#include <File.au3> #include <Array.au3> Opt("TrayAutoPause", 0) Global $sOnlineFile = "Online.txt" Global $sOfflineFile = "Offline.txt" Global $sOutputFile = "Log.txt" Global $iDelay = 100 While 1 $sOutput = "" $sOutput = $sOutput & CheckOnline() $sOutput = $sOutput & CheckOffline() ;If $sOutput <> "" Then Output($sOutput) Sleep($iDelay) WEnd ;_FileDeleteLine("Online.txt", "abc") Func CheckOnline() Local $aRecords Local $sToReturn If Not _FileReadToArray($sOnlineFile,$aRecords) Then Return " Error reading log to Array error:" & @error EndIf For $x = 1 to $aRecords[0] If Ping($aRecords[$x]) = 0 Then $sToReturn = $sToReturn & " " & $aRecords[$x] & " went offline" & @CRLF FileWriteLine($sOfflineFile, $aRecords[$x]) MsgBox(0,"","|" & $sOfflineFile & "," & $aRecords[$x] & "|") _FileDeleteLine($sOnlineFile, $aRecords[$x]) EndIf Next _ArrayDelete($aRecords, 0) _FileWriteFromArray($sOnlineFile, $aRecords) Return $sToReturn EndFunc Func _FileDeleteLine($sFileName, $sToDelete) Local $aRecords _FileReadToArray($sFileName, $aRecords) Local $File = FileOpen($sFileName, 2) For $x = 1 to $aRecords[0] If $aRecords[$x] == $sToDelete Then Else FileWriteLine($File, $aRecords[$x]) EndIf Next FileClose($File) EndFunc _FileDeleteLine("Online.txt", "abc") works, but if I have "abc" in the Online.txt file, that line does not get deleted. Any suggestions? Edited September 26, 2008 by Prab FolderLog GuiSpeech Assist Link to comment Share on other sites More sharing options...
enaiman Posted September 25, 2008 Share Posted September 25, 2008 Am I the only one confused?_FileDeleteLine("Online.txt", "abc") works and if I have "abc" in the Online.txt file, that line does not get deletedlooks like a contradiction: if your function works (1st part is true) then it will delete the record so the 2 nd part is falseif your function doesn't work (1st part false) then the record is not deleted therefore the 2nd part is true...What should I understand? SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
Prab Posted September 26, 2008 Author Share Posted September 26, 2008 I solved this issue. What I meant was if I ran just _FileDeleteLine("Online.txt", "abc") it worked, but if I ran Func CheckOnline() when it called _FileDeleteLine it did not work. The issue was that _FileDeleteLine worked the whole time but at the end of the function I had FileWriteFromArray($sOnlineFile, $aRecords) which would add back all the lines that I just deleted. Oops. FolderLog GuiSpeech Assist 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