Yargo Posted July 12, 2009 Share Posted July 12, 2009 Hi,Let's say I have a script called "main_program.au3" which includes "included_file.au3".When I wish to print debug messages, I use the following:debug_print (@ScriptName, @ScriptLineNumber, "Debug message").The 'debug_print' function is very simple:Func debug_print ($fileName, $lineNumber, $msg) Local $message $message = "================================================================" & @CRLF $message = $message & "Origin : " & $fileName & "@(" & $lineNumber & ")" & @CRLF $message = $message & "Message : " & $msg & @CRLF ConsoleWrite($message)EndFuncHowever, no matter if I put this call for "debug_print" in the "main_program.au3" or in the "included_file.au3", it shows only "main_program.au3" and never "included_file.au3".What am I missing here ?TIA,Yaron Golan Link to comment Share on other sites More sharing options...
dantay9 Posted July 12, 2009 Share Posted July 12, 2009 (edited) I am not quite sure what you are asking. When you include a file and run a program, a single program is run. That program includes all functions and variables in the included file. The @scriptname macro applies to the program running it. The program you are running is Main.au3 so @scriptname applies to Main.au3. If you put it in included.au3, that file is included in Main.au3 and Main.au3 is run. Since it is Main.au3 that is running the @scriptname still applies to Main.au3. The only way for the macro to apply to included.au3 is if included.au3 is the file that is being run. Hope this clears a little bit up. Edited July 12, 2009 by dantay9 Link to comment Share on other sites More sharing options...
Yargo Posted July 12, 2009 Author Share Posted July 12, 2009 I am not quite sure what you are asking. When you include a file and run a program, a single program is run. That program includes all functions and variables in the included file. The @scriptname macro applies to the program running it. The program you are running is Main.au3 so @scriptname applies to Main.au3. If you put it in included.au3, that file is included in Main.au3 and Main.au3 is run. Since it is Main.au3 that is running the @scriptname still applies to Main.au3. The only way for the macro to apply to included.au3 is if included.au3 is the file that is being run. Hope this clears a little bit up.Hi,Thanks for the answer. I figured it'll be the answer.Is there a way (besides hardcoding) to have the ability to know where in the code a debug message is printed out from? Link to comment Share on other sites More sharing options...
dantay9 Posted July 12, 2009 Share Posted July 12, 2009 If you are just testing, hardcoding wouldn't be a bad idea. Just delete the lines when you are ready to compile. If you use ConsoleWrite, you don't even have to remove the lines because they aren't visible when compiled. Here is another way to debug when the code is compiled. Func dbg($msg) ;use debugview from sysinternals ;http://technet.microsoft.com/en-us/sysinternals/bb896647.aspx Download ;http://msdn.microsoft.com/en-us/library/ms679303(VS.85).aspx Functions DllCall("kernel32.dll", "none", "OutputDebugString", "str", $msg) EndFunc ;==>dbg Download from the link, run the program, then run your script compiled. Wherever you have "dbg($debuggingmessage)", it will show up on the debugview console. This works for both .au3 scripts and compiled scripts but is most helpful in compiled scripts because it doesn't slow down the script like msgbox. For testing, hardcoding is probably the best answer. 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