Debugging common errors

Proteus, just like any other programming language, requires a little attention when writing programs; many concepts common to C and Pascal are also applicable to Proteus, being a structured language.

You should insert print instructions to display the values of significative variables at a certain point, since there is no debugger to trace execution step-by-step. An easy way to obtain the list of values for all public identifiers is using the method DEBUG, which prints all the values in the three possible interpretations (string, integer number, floating point number). You can not view local variables by using this method, nor the values of the items inside data structures (queues, stacks, arrays, etc.); to verify single values, use CONSOLE or CONSOLELN.

Since you can write endless loops, you should pay attention to exit conditions and consider an "emergency exit", like the one illustrated below:

; We are not sure that the loop always ends - we decide to exit the loop after
; 10 seconds anyway
ExitTime = ADD(CLOCK(), 10)
WHILE Test
  ...
  IF GT(CLOCK(), ExitTime)
    BREAK
  FI
LOOP

A common error is using the character '\' inside strings without considering the expansion of C-like constants; for example, the following Dos path is wrong:

PathName = "C:\DOS\ATTRIB.EXE"

It is actually interpreted in this way: C:[0]DOS[10]TTRIB.EXE, where [0] and [10] are the ASCII characters 0 and 10. The right path is the following:

PathName = "C:\\DOS\\ATTRIB.EXE"

Another common error is using string comparison functions in place of numeric comparison functions; the first have in their name the prefix STR: STREQ, STRNEQ, while the second don't have any prefix: EQ, NEQ.

Logical functions sometimes are also confused with binary operations (which all have the common prefix N); the binary AND of two numbers is NAND, the logical counterpart is AND; the same holds for or, xor, not.

Side-effects (collateral effects) are often a source of troubles; for example, if you call REXMATCH inside a UDF, you should consider that the predefined identifiers R_START and R_LENGTH are also modified outside of the function.

A common mistake for people writing their first Proteus programs is adding unrequired parenthesis, like in the following example:

IF (OS)
  CONSOLELN "Operating system: Ms-Dos™ or Windows™"
FI

When the script is run, Proteus reports an error on the line beginning with IF; the parenthesis are used in Proteus only when defining or calling functions, because the order in which operations are performed is implicitly determined.
IF, WHILE, SWITCH and FOR do not require parenthesis in their conditions, as opposed to C.

Another common mistake is using SET in place of PSET inside a UDF to update a public variable, or forgetting using PUB on a public identifier inside a user defined function.

Examples.

; Error! MONTHS, being SET, is a variable local to ONSTART; 
; the public variable MONTHS remains untouched, so the function ONSTART
; does not have any effect
FUNCTION ONSTART

  MONTHS = "Gen Feb Mar Apr Mag Giu Lug Ago Set Ott Nov Dic"
RETURN 


; Error! R_START and R_LENGTH are not inside PUB; since they were not
; initialized before being referenced, they will crash the program
FUNCTION GetTag(s)

  IF REXMATCH(s, "<.*>")
    RETURN SUBSTR(s, R_START, R_LENGTH)
  FI
RETURN ""

A few suggestions:

Start of page Next topic Previous topic Contents Index
Midnight Lake iPhone Case Black Women Shoes Black Flat Shoes Leather Flats Black Patent Ballerinas Black Ballet Shoes Casual Shoes Black Shoes Women Balle Record Player Cufflinks Best iPhone XR Clear Cases iPhone XS/XS Max Leather Cases Sale Best iPhone 8/8 Plus Silicone Cases iPhone 7/7 Plus Cases & Screen Protector New Cases For iPhone 6/6 Plus iPhone 8 Case Sale iPhone Xr Case Online iPhone 7 Case UK Online iPhone X Case UK Sale iPhone X Case Deals iPhone Xs Case New Case For iPhone Xr UK Online Case For iPhone 8 UK Outlet Fashion Silver Cufflinks For Men Best Mens Cufflinks Outlet Online The Gold Cufflinks Shop Online Cheap Shirt Cufflinks On Sale Nice Wedding Cufflinks UK Online Top Black Cufflinks UK Online Mens Cufflinks Online Silver Cufflinks For Men Men Cufflinks UK Sale Gold Cufflinks UK Online Gold Cufflinks UK Silver Cufflinks UK Shirt Cufflinks Discount Online Mens Cufflinks Deals & Sales Girls Shoes For Dance Fashion Ballet Dance Shoes Best Ballet Flats Shoes UK Online Cheap Ballet Pointe Shoes UK Online Best Ballet Shoes Outlet Best Dance Shoes Sale Cheap Ballet Flats Sale UK Best Pointe Shoes Online UK Ballet Dance Shoes UK Shoes For Dance UK Best Ballet Slippers Shop Best Yoga Shoes Hotsell