Jump to content
Sign in to follow this  
redpicker

Line Number in message box display

Recommended Posts

redpicker

I couldn't find anything on this in the help files or by searching the forum, so I'll ask.

Is there a way to automatically have the message box display the line number that called it? 

I use the msgboxes a lot in debugging and I have started putting the line number as the title of the msgbox:

EX:

Msgbox (0,"-57-","The value for $stringinput is not as expected == " & $stringinput)

which stops the script at line 57 and tells me why.

Unfortuantely, as I add lines above line 57, this message box can easliy get moved. If I paste in a lot of stuff, it can be moved down 100 lines, or more.  Of course, if this happens and I don't change the title of the msgbox, I start looking at line 57 to figure out why the variable isn't as expected and I can have trouble when it isn't where I expect it.

Of course, I can just search for "-57-" and I can find it, but if there was a way for the msgbox function to automatically display the line number, it would be helpful.

Thanks,

redpicker

Share this post


Link to post
Share on other sites
FireFox

Hi,

The @ScriptLineNumber macro maybe? (only works in non compiled mode).

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
water

Try macro @ScriptLineNumber.

According to the docu: "Line number of the currently executed script line. Useful for debug statements specially when a function is call you can pass the caller line number. (Not significant in complied script)"


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
AdmiralAlkex

To automatically get the line number you can set @ScriptLineNumber as a default value for a optional function parameter, then the function will know when it was called from.

Example:

Local $stringinput = "test abc"
_MsgBox("The value for $stringinput is not as expected == " & $stringinput)
_MsgBox("The value for $stringinput is not as expected == " & $stringinput)

_MsgBox("The value for $stringinput is not as expected == " & $stringinput)

Func _MsgBox($sText, $sTitle = @ScriptLineNumber)
    MsgBox(0, "-" & $sTitle & "-", $sText)
EndFunc
  • Like 3

Share this post


Link to post
Share on other sites
redpicker

That's great!  I am not surprised that hadn't run across that before; I really don't understand much of this stuff.  I hack away and have figured out a lot, but there is so much that I don't know that I am amazed that I have been able to do what I can do.

I would really like to figure out how to use the debugger, but I feel that it is over my head.  I know it really isn't, but I just haven't had the time to figure it out.  Maybe Pincopanco's link will do the trick.  I'll give it a look.

Thanks, again!

Share this post


Link to post
Share on other sites
cal

My defalut mesg box for years has been defined in the abbreviations file as

mb=MsgBox(0, @ScriptName,  'Line ' & @ScriptLineNumber & @CRLF & '---' & $| & '---')
mbb=MsgBox(0, @ScriptName,  'Line ' & @ScriptLineNumber & @CRLF & '--- | ---')

recently I added.

mbe=MsgBox(0, @ScriptName,  'Line ' & @ScriptLineNumber & @CRLF & @CRLF & 'error ---' & @error & '---' & @CRLF & 'extented ---' & @extended & '---' & @CRLF & @CRLF & 'will exit')|nExit
 

type the key and hit space.  Instant custom mesgbox with cursor placed where you need it next, to type the var in one case or a text note in the other.   The dashes are for easy detection of spaces at the start or end of your var if it happens to be a string.  Downside is it can be hard to tell at a glance if it was a neg number.   ----1---   and ---1---   look pretty close.  3 dashes and a neg are close to 3 dashes in a mesg box.

I had a thought this afternoon.  I wonder if I can stick @compiled in there somehow and removed the end result of  "line -1" that a compiled version gives on the mesgbox while leaving it there for the script vers to still give actual line numbers.  But I have not played yet with that idea.  I want to keep it to one line.  I often use "mb" or "mbb" as quick tests and then the editors hotkey Ctrl Q to comment and uncomment the mesgbox lines as needed.  Hence my desire to keep it to a single line.

Be aware that @scriptname can't tell if something is in an include you wrote or the calling script.  Includes get counted as the reg script and returns that name, not its own.  Found that out the hard way when I was using some vars that where defined in both.  Last one wins in that case.   lol

I need to stop getting lazy with the global vars in cases like that.

Share this post


Link to post
Share on other sites
cal

ah.

mb=MsgBox(0, @ScriptName, StringReplace('Line ' & @ScriptLineNumber,'Line -1','') & @CRLF & '---' & $| & '---')

does the trick.

Hmm.  Now I miss the familar -1.   I think I'll leave it as it was.

Share this post


Link to post
Share on other sites
TXTechie

cal,

You can include parenthesis "()" so that you can see the negative numbers (like -1)... I often do this to see the full variable result including spaces too:

$mb=MsgBox(0, @ScriptName,  'Line ' & @ScriptLineNumber & @CRLF & '---' & ' (' & $| & ') ' & '---')

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  

×