Page 1 of 1 1
Topic Options
#43768 - 2003-08-07 10:57 AM Skip parts of code when in debug
Darren_W Offline
Hey THIS is FUN
*****

Registered: 2001-10-10
Posts: 208
Loc: Bristol, England
I would like to skip a portion of code when I debug a piece of code, using if-endif I suppose.

Is there a Macro ref or anything I can check to do this.

[ 07. August 2003, 10:58: Message edited by: Darren ]
_________________________
I want to share something with you - the three sentences that will get you through life.
Number 1, 'cover for me.'
Number 2, 'oh, good idea, boss.'
Number 3, 'it was like that when I got here'.

Top
#43769 - 2003-08-07 11:45 AM Re: Skip parts of code when in debug
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Basically, DIY. Here's what I do:
  • Create a global debug variable, use in debug statement.
  • Create a global log level variable, only log messages which comply.
The point of the log level is that it allows me to increase the amount of messages output when developing or debugging and reduce when in production without changing the code.
Using a global debug means that sections of code can be conditionally executed.

code:
Global $gDEBUG      $gDEBUG="ON"
Global $gLOGLEVEL $gLOGLEVEL=9 ; 9=Verbose debug messages, 0=Normal

DEBUG $gDEBUG

The logging routine looks like this:
code:
Function Log($iLevel,$sMessage)
If $iLevel <= $gLOGLEVEL @TIME+" "+$sMessage EndIf
EndFunction

Say you have the following spread throughout your code:
code:
If $gDEBUG="ON"
; This code only executed when in debug.
EndIf

Log(0,"This is a fatal error message, always displayed"+@CRLF)
Log(1,"Probaly some sort of informational message, like a startup/shutdown message"+@CRLF)
Log(9,"A very verbose message - only displayed when detailed debugging is needed"+@CRLF)

Now, set $gDEBUG to "ON" or "OFF" depending on your mood. Set $gLOGLEVEL to the verbosity of messages you require.

These are cut down examples which you should expand as you need, for example in my scritps having debug on causes the log UDF to write all messages to a debug log file, while only displaying on screen those that meet the $gLOGLEVEL criteria.

Top
#43770 - 2003-08-07 11:58 AM Re: Skip parts of code when in debug
Darren_W Offline
Hey THIS is FUN
*****

Registered: 2001-10-10
Posts: 208
Loc: Bristol, England
Thanks, that does the trick [Smile]
_________________________
I want to share something with you - the three sentences that will get you through life.
Number 1, 'cover for me.'
Number 2, 'oh, good idea, boss.'
Number 3, 'it was like that when I got here'.

Top
#43771 - 2003-08-07 02:59 PM Re: Skip parts of code when in debug
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
See also the DisplayText() - Display text incl. logging option UDF which offers multiple levels of screen and/or file logging options.
_________________________
There are two types of vessels, submarines and targets.

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 2009 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.213 seconds in which 0.11 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org