PDA

View Full Version : for/next problem ?



Lionheart008
19-11-2009, 00:35
don't know if this for/next example could be a problem, but I have got an general protection fault with this example:


uses "console"

dim a,b as long

Const Mazda = 8
Const Ferrari = 16
Const Phantom = 32
Const Star = 64

Dim car(Mazda) as long
Dim racer(Ferrari) as long
Dim jet(Phantom) as long
Dim earth(Star) as long

for a = 1 to Mazda
car(a) = 0
racer(a) = 0
jet(a) = 0
next a
printl "one: ok " + a

for a = 1 to Ferrari
car(a) = 0
racer(a) = 0
jet(a) = 0
next a
printl "two: ok " + a


for a = 1 to Star
car(a) = 0
racer(a) = 0
jet(a) = 0
earth(a) = 0
next a
printl "four: ok " + a

for a = 1 to Phantom
car(a) = 1 '-- allowed?
racer(a) = 10 '-- allowed?
jet(a) = 100 '-- allowed?
earth(a) = 1000 '-- allowed?
next a
printl "gpf! three: not ok " + a

waitkey

"phantom" isn't ok at all.

best regards, Frank

ErosOlmi
19-11-2009, 00:48
You are going out of array bounds.