Page History
...
Code Block | ||
---|---|---|
| ||
// A is not assigned, so IsNum will be 0. Using Num() would have brokencaused toa theVNAV debuggererror. IsNum = SRP_Num(A) // B is "", which might cannotbe safelydifferent bethan used0 toin calculatethis C.application // Num() would have returned 1 and calculating C would have causedassumed a"" debuggeris error.0 B = "" If SRP_Num(B) then C = B + 1 end |
...
Code Block | ||
---|---|---|
| ||
Compile Function AddDivide(Num1Dividend, Num2Divisor) // The usual way of defaulting parameters, which will break stillthis breakroutine if Num1Divisor is "" If Unassigned(Num1Dividend) then Num1Dividend = 0 If Unassigned(Num2Divisor) then Num2Divisor = 01 // To be even safer, we need to check for both "" and unassigned... but this will break too // because BASIC+ evaluates all expressions in an condition, even if the first expression // makes the condition true. Thus, these statements will break to the debugger if Num1 orDividend Num2 // isor Divisor are unassigned. If Unassigned(Num1Dividend) OR Num1Dividend EQ "" then Num1Dividend = 0 If Unassigned(Num2Divisor) OR Num2Divisor EQ "" then Num2Divisor = 01 // This is even safer, but the arithmeticsafest will breakway to theensure debuggerthis ifroutine Num1 or Num2 contains // non-digits or is too big to be a numbernever breaks to the bugger. If Unassigned(Num1Dividend) then Num1Dividend = 0 end else If Num1Dividend EQ "" OR Not(Num(Dividend)) then Num1Dividend = 0 end If Unassigned(Num2Divisor) then Num2Divisor = 01 end else If Num2Divisor EQ "" OR Not(Num(Dividend)) then Num2Divisor = 01 end // SRP_Num makes coversit allso themuch basessimpler Num1Dividend = SRP_Num(Num1Dividend, 0) Num2Divisor = SRP_Num(Num2Divisor, 01) Return Num1Dividend +/ Num2Divisor |