This will produce error with VB(Subscript out of range) , but not with FB
Can somebody expain why ?
Code: Select all
Dim mem(0) As Integer
Dim i As Integer
For i = 0 To 10
mem(i) = i
Next
Code: Select all
Dim mem(0) As Integer
Dim i As Integer
For i = 0 To 10
mem(i) = i
Next
It is a memory allocation method.jona wrote:I thought I understood arrays, ...
Code: Select all
#lang "fb"
'' NOTICE THE ORDER IN WHICH THE ARRAYS ARE DEFINED
Dim as integer kim(10), mem(1 to 5), mim(10), i, j=20
FOR I=0 TO 10:mim(i)=100+i:kim(i)=200+i:next i
i=lbound(mem) : print "mem() low bound is ";i
i=ubound(mem) : print "mem() high bound is ";i
'' this exceeds the defined array limits
For i = 0 To j : mem(i) = 2*i : Next i
print " "
print "kim(0 to 20)"
for i=0 to j: print kim(i); :next i:print " "
print " "
print "mem(0 to 20)"
for i=0 to j : print mem(i); :next i : print " "
print " "
print "mim(0 to 20)"
for i=0 to j: print mim(i); :next i: print " "
sleep
end
Code: Select all
#lang "fb"
Dim i As Integer
Dim mem(1 to 5) As Integer
i=lbound(mem)
print "low bound is ";i
i=ubound(mem)
print "high bound is ";i
For i = 0 To 15
mem(i) = 2*i
Next i
for i=0 to 15
print mem(i)
next i
sleep
end
Code: Select all
low bound is 1
high bound is 5
0
2
4
6
8
10
6
0
1245120
4199390
1
3361896
3355304
26
28
30
Where is a discussion of compiler options: what they do and how to invoke them? I'm using FBIde.fxm wrote: Remark: only the compile option -exx allows to check the array bounds at runtime.
How do I invoke them from FBIde?fxm wrote:CatPgCompOpt
Thanks. I spent a good hour searching for this information before posting my follow up question. Normally all I need is to pointed in the right direction and then I can find my way.fxm wrote:See in forum beginners:
Recommended settings for FBIde users