News:

  • September 27, 2026, 01:59:10 PM

Login with username, password and session length

Author Topic: Array Out of Bounds  (Read 6336 times)

RBPLC

  • Hero Member
  • *****
  • Posts: 586
Array Out of Bounds
« on: January 29, 2022, 01:58:08 PM »
No matter how I rearrange the MATH statement, when vInjCounter = 0 I get an array out of bounds error. Why is this giving the array out of bounds when the IF is attempting to prevent this? I've rearranged the IF arguments every way and it still gives the error.

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6176
  • Yes Pinky, Do-more will control the world!
Re: Array Out of Bounds
« Reply #1 on: January 29, 2022, 02:21:03 PM »
No matter how I rearrange the MATH statement, when vInjCounter = 0 I get an array out of bounds error. Why is this giving the array out of bounds when the IF is attempting to prevent this? I've rearranged the IF arguments every way and it still gives the error.

Unlike a high level language, the MATH IF() executes both sides always, it's just choosing which one to assign. The easy answer is to just clear the error immediately after the instruction, but it shouldn't be hard to use a MAX(vInjCounter-1, 0) on the index to prevent it from ever being negative in the case you aren't using.
« Last Edit: January 29, 2022, 02:23:08 PM by BobO »
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO