Hi All,
One for the newbies, or the oldies who like us didn't realise....
Recently changed some code, which resulted in a runtime error for a
client, and it took us a while to track it down.
As per the example code below, it appears that redefining an array
variable and resetting its size it does NOT automatically reset the
numeric value of the array variable. You actually need to use Clear
Variable, or explicitly use aGrower:=0 in the code. Otherwise if some
other form code/script makes use of the aGrower variable (for example),
before you have added more rows, then you'll get a runtime error:
ARRAY TEXT(aGrower;0)
APPEND TO ARRAY(aGrower;"One")
APPEND TO ARRAY(aGrower;"Two")
ALERT(String(aGrower)) // Result is "0"
aGrower:=2
ARRAY TEXT(aGrower;0)
ALERT(String(aGrower)) // Result is "2"
CLEAR VARIABLE(aGrower)
ARRAY TEXT(aGrower;0)
ALERT(String(aGrower)) // Result is "0"
I've tested this as far back as 4D v11 and the behaviour is the same.
It seems that we just haven't run into the situation in our code before,
where the array variable is used after having previously reset the array
size to zero.
-------
Cheers,
Allan Udy
Golden Micro Solutions Ltd, Blenheim, New Zealand
http://www.golden.co.nz<http://www.golden.co.nz>
**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ: http://lists.4d.com/faqnug.html
Archive: http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub: mailto:[email protected]
**********************************************************************