darkshadow791 Posted October 14, 2006 Share Posted October 14, 2006 Hi, I have a program that I usually leave running that closes error windows, specifically my bluetooth errors that I get periodically. I want to be able to write a file to an ini or any other type of file every time it closes one of those windows. Here is the base code: expandcollapse popup#include <GuiConstants.au3> #include <File.au3> Opt("TrayMenuMode", 1) Opt("TrayAutoPause",0) If Not FileExists("Log.ini") Then FileWrite("Log.ini") Dim $log_count = _FileCountLines(".\Log.ini") GuiCreate("Bluetooth Debugger", 250, 200,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)) $Date_1 = GuiCtrlCreateDate("Select Date", 10, 10, 230, 20) $Input_2 = GuiCtrlCreateInput("", 10, 40, 230, 120) $Button_3 = GuiCtrlCreateButton("Minimize", 10, 170, 110, 20) $Button_4 = GuiCtrlCreateButton("Exit", 130, 170, 110, 20) $Tray_ShowGUI = TrayCreateItem("Show GUI") $Tray_Exit = TrayCreateItem("Exit") ShowGUI() Func ShowGUI() GuiSetState() While 1 $msg2 = TrayGetMsg() $msg = GuiGetMsg() Switch $msg Case $GUI_EVENT_CLOSE ExitLoop Case $Date_1 MsgBox(0,"test","this is a test") Case $Button_3 ExitLoop Case $Button_4 _Exit() EndSwitch WEnd GUISetState(@SW_HIDE) Mainloop() EndFunc Func Mainloop() While 1 If WinExists("Bluetooth Support Server") Then WinClose("Bluetooth Support Server") EndIf If WinExists("ZoneAlarm Pro", "Bluetooth") Then WinActivate("ZoneAlarm Pro") ControlClick("ZoneAlarm Pro","&Allow",6) EndIf If WinExists("Bluetooth Tray Application") Then ControlClick("Bluetooth Tray Application","&Don't Send",1001) EndIf $msg2 = TrayGetMsg() Switch $msg2 Case $Tray_ShowGUI ShowGUI() Case $Tray_Exit _Exit() EndSwitch WEnd EndFunc Func _Exit() $Quit = MsgBox(4,"Exit?","Are you sure you want to exit?") If $Quit = 6 Then MsgBox(4096,"Exiting","Goodbye!",100) Exit Else Mainloop() EndIf EndFunc I want to write a date and time stamp every time "If WinExists("Bluetooth Tray Application") Then" happens, since it will happen after the other 2 windows pop up. Then when they show the gui via the tray or running it again, they can select a date from the guictrlcreatedate and all times that the window has occured will show up in the input, with the time on it. Simply put: My program checks to see if any bluetooth crashing errors occur. If the last of the three occur, I want my program to write to a log file with the date and time on it every time it happens. Then, with the gui I might want to see days and/or times this has happened, and I will select a date from the date gui and the times of that date will be displayed in the input area, preferrably numbered. I.E.: on 10/15/06 at 10:52 AM this happens, and again at 2:21 PM - it writes to a log file. I look at the gui and select that date. In the input I want to see something like 1. 10:52 AM 2. 2:21 PM or something to this matter. I've tried it a bit with some other programs but I'm really not that good at doing it. Any suggestions, pointers, methods, links, etc is greatly appreciated. Thanks! Note Taker Lite - a note taking / converting tool. Link to comment Share on other sites More sharing options...
Xenobiologist Posted October 14, 2006 Share Posted October 14, 2006 (edited) Hi, did you look at _FileWriteToLog() ? Edit: It depends on your regional settings. expandcollapse popup#include <GuiConstants.au3> #include <File.au3> #include <Date.au3> HotKeySet("1", "_log") Opt("TrayMenuMode", 1) Opt("TrayAutoPause", 0) Global $LogPath = "Bluetooth.log" Global $count = 0 GUICreate("Bluetooth Debugger", 450, 200, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)) $Date_1 = GUICtrlCreateDate("Select Date", 10, 10, 230, 20, $DTS_SHORTDATEFORMAT) $Input_2 = GUICtrlCreateEdit("", 10, 40, 430, 120, $ES_MULTILINE + $WS_VSCROLL) $Button_3 = GUICtrlCreateButton("Minimize", 10, 170, 110, 20) $Button_4 = GUICtrlCreateButton("Exit", 130, 170, 110, 20) $Tray_ShowGUI = TrayCreateItem("Show GUI") $Tray_Exit = TrayCreateItem("Exit") ShowGUI() Func ShowGUI() GUISetState() While 1 $msg2 = TrayGetMsg() $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE ExitLoop Case $Date_1 ;MsgBox(0, "test", "this is a test") _search() Case $Button_3 ExitLoop Case $Button_4 _Exit() EndSwitch WEnd GUISetState(@SW_HIDE) Mainloop() EndFunc ;==>ShowGUI Func Mainloop() While 1 If WinExists("Bluetooth Support Server") Then WinClose("Bluetooth Support Server") EndIf If WinExists("ZoneAlarm Pro", "Bluetooth") Then WinActivate("ZoneAlarm Pro") ControlClick("ZoneAlarm Pro", "&Allow", 6) EndIf If WinExists("Bluetooth Tray Application") Then ControlClick("Bluetooth Tray Application", "&Don't Send", 1001) $count += 1 _FileWriteLog($LogPath, $count & " : Window closed") EndIf $msg2 = TrayGetMsg() Switch $msg2 Case $Tray_ShowGUI ShowGUI() Case $Tray_Exit _Exit() EndSwitch WEnd EndFunc ;==>Mainloop Func _Exit() $Quit = MsgBox(4, "Exit?", "Are you sure you want to exit?") If $Quit = 6 Then MsgBox(4096, "Exiting", "Goodbye!", 100) Exit Else Mainloop() EndIf EndFunc ;==>_Exit Func _log() $count += 1 _FileWriteLog1($LogPath, $count & " : time") EndFunc ;==>_log Func _search() MsgBox(0, "", GUICtrlRead($Date_1)) Dim $aRecords If Not _FileReadToArray($LogPath, $aRecords) Then MsgBox(4096, "Error", " Error reading log to Array error:" & @error) Exit EndIf For $x = 1 To $aRecords[0] If StringInStr($aRecords[$x], GUICtrlRead($Date_1)) <> 0 Then GUICtrlSetData($Input_2, GUICtrlRead($Input_2) & @CRLF & $aRecords[$x]) EndIf Next EndFunc ;==>_search Func _FileWriteLog1($sLogPath, $sLogMsg) ;============================================== ; Local Constant/Variable Declaration Section ;============================================== Local $sDateNow Local $sTimeNow Local $sMsg Local $hOpenFile Local $hWriteFile $sDateNow = @MDAY & "." & @MON & "." & @YEAR $sTimeNow = @HOUR & ":" & @MIN & ":" & @SEC $sMsg = $sDateNow & " " & $sTimeNow & " : " & $sLogMsg $hOpenFile = FileOpen($sLogPath, 1) If $hOpenFile = -1 Then SetError(1) Return 0 EndIf $hWriteFile = FileWriteLine($hOpenFile, $sMsg) If $hWriteFile = -1 Then SetError(2) Return 0 EndIf FileClose($hOpenFile) Return 1 EndFunc ;==>_FileWriteLog1 So long, Mega Edited October 14, 2006 by th.meger Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
darkshadow791 Posted October 14, 2006 Author Share Posted October 14, 2006 (edited) Thanks! It looks like it should work. I'll let you know if there are any problems Edited October 14, 2006 by darkshadow791 Note Taker Lite - a note taking / converting tool. Link to comment Share on other sites More sharing options...
darkshadow791 Posted October 14, 2006 Author Share Posted October 14, 2006 Hmm... it doesn't seem to be modifying the input correctly, and I don't fully understand the code you gave me... any idea's as to why? also, it seems that there is two different log outputs... this isn't really wanted... All i really want the input field to show is (hopefully) A number and the time when i select a date, but if a date has no logs then it wont show anything... if not that then maybe just the time... I've been trying to figure it out but no luck so far... Note Taker Lite - a note taking / converting tool. Link to comment Share on other sites More sharing options...
tresa Posted October 14, 2006 Share Posted October 14, 2006 Hmm... it doesn't seem to be modifying the input correctly, and I don't fully understand the code you gave me... any idea's as to why? also, it seems that there is two different log outputs... this isn't really wanted... All i really want the input field to show is (hopefully) A number and the time when i select a date, but if a date has no logs then it wont show anything... if not that then maybe just the time... I've been trying to figure it out but no luck so far... Here I improved the code in several ways 1 - I put together all infos and funcs for the GUI and the Tray 2 - They are embrassed in #region tag so that you can hide/show them 3 - You can even put them in an #include file 4 - I changed the main loop so that the tray and GUI watch are in the same loop avoiding cascading calls that are big bug sources 5 - Note : the Hotkey is there just for me to create logfile lines expandcollapse popup#include <GuiConstants.au3> #include <File.au3> #include <Date.au3> HotKeySet("1", "_log") Func _log() MsgBox(0,"","Info") trackEvent("KeyPress '1'") GUIDisplay() EndFunc ;==>_log Global $LogPath = "Bluetooth.log" Global $count = 0 #region GUI vars, defs & funcs *************************** dim $GUI_On = 0 dim $Date_1,$Input_2,$Button_3,$Button_4 Func GUIInit() GUICreate("Bluetooth Debugger", 450, 200, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)) $Date_1 = GUICtrlCreateDate("Select Date", 10, 10, 230, 20, $DTS_SHORTDATEFORMAT) $Input_2 = GUICtrlCreateEdit("", 10, 40, 430, 120, $ES_MULTILINE + $WS_VSCROLL) $Button_3 = GUICtrlCreateButton("Minimize", 10, 170, 110, 20) $Button_4 = GUICtrlCreateButton("Exit", 130, 170, 110, 20) EndFunc Func GUIDisplay() if $GUI_On=0 then GUISetState() $GUI_On=1 EndIf listInfosGUI() EndFunc Func GUIHide() $GUI_On=0 GUISetState(@SW_HIDE) EndFunc Func GUICheck() if $GUI_On=0 then Return $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE,$Button_3 GUIHide() Case $Date_1 listInfosGUI() Case $Button_4 _Exit() EndSwitch EndFunc Func listInfosGUI() dim $texte="" Dim $aRecords If Not _FileReadToArray($LogPath, $aRecords) Then MsgBox(4096, "Error", " Error reading log to Array error:" & @error) Exit EndIf For $x = $aRecords[0] to 1 Step -1 If StringInStr($aRecords[$x], GUICtrlRead($Date_1)) <> 0 Then $texte=$texte & @CRLF & $aRecords[$x] EndIf Next GUICtrlSetData($Input_2, StringMid($texte,3)) EndFunc ;==>_search #endregion GUI*********************************************** #region tray vars, defs & funcs************************************* dim $Tray_Exit,$Tray_ShowGUI Func TrayInit() Opt("TrayMenuMode", 1) Opt("TrayAutoPause", 0) $Tray_ShowGUI = TrayCreateItem("Show GUI") $Tray_Exit = TrayCreateItem("Exit") EndFunc Func TrayCheck() $msg2 = TrayGetMsg() Switch $msg2 Case $Tray_ShowGUI GUIDisplay() Case $Tray_Exit _Exit() EndSwitch EndFunc #endregion tray***************************************** #region Main Program*********************************** TrayInit() GUIInit() GUIDisplay() While 1 GUICheck() checkBlueTooth() TrayCheck() WEnd #endregion Main Program*********************************** #region BlueTooth******************************************** Func checkBlueTooth() If WinExists("Bluetooth Support Server") Then WinClose("Bluetooth Support Server") trackEvent("BlueTooth Support") EndIf If WinExists("ZoneAlarm Pro", "Bluetooth") Then WinActivate("ZoneAlarm Pro") ControlClick("ZoneAlarm Pro", "&Allow", 6) trackEvent("ZoneAlarm Pro") EndIf If WinExists("Bluetooth Tray Application") Then ControlClick("Bluetooth Tray Application", "&Don't Send", 1001) trackEvent("BlueTooth Tray") EndIf EndFunc Func _Exit() $Quit = MsgBox(32+4, "Exit?", "Are you sure you want to exit?") If $Quit = 6 Then MsgBox(4096+64, "Exiting", "Goodbye!", 100) Exit EndIf EndFunc ;==>_Exit Func trackEvent($sLogMsg) Local $sMsg Local $hOpenFile $count+=1 $sMsg = @MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & " : " & $count & " : " & $sLogMsg $hOpenFile = FileOpen($LogPath, 1) If $hOpenFile = -1 Then Return -1 If FileWriteLine($hOpenFile, $sMsg) <> 1 Then Return 0 FileClose($hOpenFile) Return 1 EndFunc ;==>_FileWriteLog1 #endregion***************************************** Link to comment Share on other sites More sharing options...
darkshadow791 Posted October 14, 2006 Author Share Posted October 14, 2006 Seems to work great except it still won't show up in the $Input area for me... is it just me? Note Taker Lite - a note taking / converting tool. Link to comment Share on other sites More sharing options...
tresa Posted October 14, 2006 Share Posted October 14, 2006 Seems to work great except it still won't show up in the $Input area for me... is it just me? You have to change the $sMsg format to be adequate versus the $Date_1 control format. In France it's 'DD/MM/YYYY' so the $sMsg in trackEvent function is : $sMsg = @MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & " : " & $count & " : " & $sLogMsgoÝ÷ ØƲm쨺»"²Ê&zØb bíý0ÏÃöaý"{aDZëa{Mú2È,¥u·ºÚ"µÍÌÍÜÓÙÈHSÓ [È ][ÝËÉ][ÝÈ [ÈQVH [È ][ÝËÉ][ÝÈ [ÈQPT [È ][ÝÈ ][ÝÈ [ÈÕT [È ][ÝÎ][ÝÈ [ÈRS [È ][ÝÎ][ÝÈ [ÈÑPÈ [È ][ÝÈ ][ÝÈ [È ÌÍØÛÝ[ [È ][ÝÈ ][ÝÈ [È ÌÍÜÓÙÓÙoÝ÷ Ø e¶¬ÆÞq«¬zØ^+-"wè°e~éܶ*'Ëç-x-ébë0'!«Ø^u«^ÕÊ'¶º%v®¶sdb7G&ætå7G"b33c¶&V6÷&G5²b33c·ÒÂuT7G&Å&VBb33c´FFUófÇC²fwC²FVà¢b33c·FWFSÒb33c·FWFRfײ5$Äbfײb33c¶&V6÷&G5²b33c·Ð¢VæD` Link to comment Share on other sites More sharing options...
tresa Posted October 14, 2006 Share Posted October 14, 2006 You have to change the $sMsg format to be adequate versus the $Date_1 control format. In France it's 'DD/MM/YYYY' so the $sMsg in trackEvent function is : $sMsg = @MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & " : " & $count & " : " & $sLogMsgoÝ÷ ØƲm쨺»"²Ê&zØb bíý0ÏÃöaý"{aDZëa{Mú2È,¥u·ºÚ"µÍÌÍÜÓÙÈHSÓ [È ][ÝËÉ][ÝÈ [ÈQVH [È ][ÝËÉ][ÝÈ [ÈQPT [È ][ÝÈ ][ÝÈ [ÈÕT [È ][ÝÎ][ÝÈ [ÈRS [È ][ÝÎ][ÝÈ [ÈÑPÈ [È ][ÝÈ ][ÝÈ [È ÌÍØÛÝ[ [È ][ÝÈ ][ÝÈ [È ÌÍÜÓÙÓÙoÝ÷ Ø e¶¬ÆÞq«¬zØ^+-"wè°e~éܶ*'Ëç-x-ébë0'!«Ø^u«^ÕÊ'¶º%v®¶sdb7G&ætå7G"b33c¶&V6÷&G5²b33c·ÒÂuT7G&Å&VBb33c´FFUófÇC²fwC²FVà¢b33c·FWFSÒb33c·FWFRfײ5$Äbfײb33c¶&V6÷&G5²b33c·Ð¢VæD`oÝ÷ Ûú®¢×¦k&ÞÊjw!jx¶´ß«²ò¶¬jëh×6 $sMsg = _now() & " : " & $count & " : " & $sLogMsg Link to comment Share on other sites More sharing options...
darkshadow791 Posted October 15, 2006 Author Share Posted October 15, 2006 Thanks it works now! Note Taker Lite - a note taking / converting tool. 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