rynodyno Posted August 7, 2008 Share Posted August 7, 2008 could someone please point me to a simple code thatshows how to creat a file using either _filecreate, dircreate, or writeline please?!!? i've looked through mny but all i could find was how to create backup batch files etc... i need to create a log file with details of error pop-ups (if it should occur).. this is the part of my code where i've tried to do this: #include <File.au3> Func _Error() If @error Then $file = FileOpen("\\zeus\$rfernando\Test Scripts\Automatic Testing\test.txt", 9) ; Check if file opened for writing OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf FileWriteLine($file, @MON & @MDAY & " " & @HOUR & @MIN & @SEC & " I am done:" & @ComputerName, @CR) MsgBox(32, "Error", "Error logged as: " & @error) EndIf FileClose($file) EndFunc ; Script Start - start synergetic Run ("S:\TCMVIC\Trial_CD_August\Synergetic\SynMain.exe arose") WinWaitActive("Information") send("{enter}") Link to comment Share on other sites More sharing options...
herewasplato Posted August 7, 2008 Share Posted August 7, 2008 The code that you have for the file creation seems okay at a glance, but it will never run.In this line of code...If @error Then@error will always be 0 going into the UDFSo nothing inside of the If/EndIf will ever run.Get rid of the If/EndIf and see how it works for you...Your code in that post does not show when and how the _Error func gets called. [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
rynodyno Posted August 7, 2008 Author Share Posted August 7, 2008 The code that you have for the file creation seems okay at a glance, but it will never run.In this line of code...If @error Then@error will always be 0 going into the UDFSo nothing inside of the If/EndIf will ever run.Get rid of the If/EndIf and see how it works for you...Your code in that post does not show when and how the _Error func gets called.how do i call it if i want this function to run everytime an error pops up?? Link to comment Share on other sites More sharing options...
herewasplato Posted August 7, 2008 Share Posted August 7, 2008 (edited) how do i call it if i want this function to run everytime an error pops up??That depends on what AutoIt can "see" when the error window pops up.You will probably want to take a look at the AdLibEnable function.maybe a layout like:$file = FileOpen("\\zeus\$rfernando\Test Scripts\Automatic Testing\test.txt", 9)AdLibEnable("_Error"); Script Start - start synergeticRun ("S:\TCMVIC\Trial_CD_August\Synergetic\SynMain.exe arose")WinWaitActive("Information")send("{enter}");rest of code here - errors may happen in hereFileClose($file)Func _Error()If WinExits("Some window title that AutoIt can see") Then FileWriteLine($file, @MON & @MDAY & " " & @HOUR & @MIN & @SEC & " I am done:" & @ComputerName, @CR)EndFuncEdit: That is a single line IF with no EndIf Edited August 7, 2008 by herewasplato [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
program builder Posted August 7, 2008 Share Posted August 7, 2008 winwaitactive("error") sleep(10) send("{enter}") sleep(10) shellexecute("filename") end of script; where it says file name put the intire file address of the file that you wish to have open every time that a error message pops up; Link to comment Share on other sites More sharing options...
rynodyno Posted August 7, 2008 Author Share Posted August 7, 2008 That depends on what AutoIt can "see" when the error window pops up. You will probably want to take a look at the AdLibEnable function. maybe a layout like: $file = FileOpen("\\zeus\$rfernando\Test Scripts\Automatic Testing\test.txt", 9) AdLibEnable("_Error") ; Script Start - start synergetic Run ("S:\TCMVIC\Trial_CD_August\Synergetic\SynMain.exe arose") WinWaitActive("Information") send("{enter}") ;rest of code here - errors may happen in here FileClose($file) Func _Error() If WinExits("Some window title that AutoIt can see") Then FileWriteLine($file, @MON & @MDAY & " " & @HOUR & @MIN & @SEC & " I am done:" & @ComputerName, @CR) EndFunc Edit: That is a single line IF with no EndIf Thank you so much for your help so far mate!! i think it's almost working.. now when an error pops up it gives me an error saying "Incorrect number of parameters in function call" I don't see anything wrong with it!! even tried 'filewrite'... no success :-( Below is what i've worked on so far... #include <File.au3> $file = FileOpen("\\zeus\$rfernando\Test Scripts\Automatic Testing\test.txt", 9) AdLibEnable("_Error") ; Script Start - start synergetic Run ("S:\TCMVIC\Trial_CD_August\Synergetic\SynMain.exe arose") WinWaitActive("Information") send("{enter}") ;Login WinWaitActive("Synergetic Login") Send("+{TAB}") Send("{DEL}") Send("sa") Send("{TAB}") Send("hersql3{#}") Send("{enter}") ;Create Staff Member Sleep(500) send("!M") Sleep(500) send("H") Sleep(500) send("S") Sleep(500) WinWaitActive("Set Staff Search Criteria") Send("!N");New Staff Member ;--------------------ERROR POPS UP HERE---------------------- WinWaitActive("Create New Staff Member") Send("MR") Send("{Enter}") Send("{Enter}") FileClose($file) Func _Error() If WinExists("DataTools Rapid Addressing Tool") Then FileWriteLine($file, @MON & @MDAY & " " & @HOUR & @MIN & @SEC & " I am done:" & @ComputerName, @CR) EndFunc ;Close Synergetic WinWaitActive("Synergetic Management System for Schools [arose]") Send("!C") Send("!F") sleep(100) Send("x") winwaitactive("Confirm") Send("Y") Link to comment Share on other sites More sharing options...
herewasplato Posted August 7, 2008 Share Posted August 7, 2008 (edited) Fix this line:If WinExists("DataTools Rapid Addressing Tool") Then FileWriteLine($file, @MON & @MDAY & " " & @HOUR & @MIN & @SEC & " I am done:" & @ComputerName, @CR)Make it:@ComputerName & @CR)or just@ComputerName)because FileWriteLine will add a "CR" if you don't. Edited August 7, 2008 by herewasplato [size="1"][font="Arial"].[u].[/u][/font][/size] 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