Page History
...
Code Block | ||
---|---|---|
| ||
Compile Function Divide(Dividend, Divisor) // The usual way of defaulting parameters, which will break this routine if Divisor is "" If Unassigned(Dividend) then Dividend = 0 If Unassigned(Divisor) then Divisor = 1 // 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 Dividend // or Divisor are unassigned. If Unassigned(Dividend) OR Dividend EQ "" then Dividend = 0 If Unassigned(Divisor) OR Divisor EQ "" then Divisor = 1 // This is the safest way to ensure this routine never breaks to the bugger. If Unassigned(Dividend) then Dividend = 0 end else If Dividend EQ "" OR Not(Num(Dividend)) then Dividend = 0 end If Unassigned(Divisor) then Divisor = 1 end else If Divisor EQ "" OR Not(Num(DividendDivisor)) then Divisor = 1 end // SRP_Num makes it so much simpler Dividend = SRP_Num(Dividend, 0) Divisor = SRP_Num(Divisor, 1) Return Dividend / Divisor |
...