Sign in to follow this  
Followers 0
Yargo

@ScriptName macro

4 posts in this topic

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)

EndFunc

However, 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

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 by dantay9

[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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.


[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0