[Gambas-user] Logical error in Gambas2.21

M. Cs. mohareve at ...626...
Mon Sep 27 11:15:54 CEST 2010


PUBLIC SUB MaxFind(tomb AS String[], minta AS String) AS Integer ' A
function in Archs module that finds the highest index in the array tomb
which contains minta
DIM supst AS String[]
DIM mfind AS Integer = -1
DIM cel AS Integer
supst = NEW String[]
supst = tomb
WHILE supst.Find(minta) <> -1
cel = supst.Find(minta)
mfind = cel
IF cel >= 0 THEN
    supst[cel] = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
ENDIF
WEND
supst.Clear
RETURN mfind
END


----------------------
'This is the problematic part: when the Arch.MaxFind() returns -1 the block
is executed and the program crashes, since an array could not have index -1.
But it means for Gambas even if -1>-1 is FALSE the block is executed!

IF Archs.MaxFind(temporal, telem) > -1 THEN
j = Archs.MaxFind(temporal, telem)
IF temporalpath[j] <> tut THEN
temporal.Add(telem)
temporalpath.Add(tut)
 ENDIF
ENDIF



More information about the User mailing list