Page History
...
Code Block | ||
---|---|---|
| ||
Compile Function Add(Num1, Num2) // The usual way of defaulting parameters, which will still break if Num1 is "" If Unassigned(Num1) then Num1 = 0 If Unassigned(Num2) then Num2 = 0 // 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 or Num2 // is unassigned. If Unassigned(Num1) OR Num1 EQ "" then Num1 = 0 If Unassigned(Num2) OR Num2 EQ "" then Num2 = 0 // This is even safer, but the arithmetic will break to the debugger if Num1 or Num2 contains // non-digits or is too big to be a number. If Unassigned(Num1) then Num1 = 0 end else If Num1 EQ "" then Num1 = 0 end If Unassigned(Num2) then Num2 = 0 end else If Num2 EQ "" then Num2 = 0 end // SRP_Num covers all the bases Num1 = SRP_Num(Num1, 0) Num2 = SRP_Num(Num2, 0) Return Num1 + Num2 |
...