Page 1 of 1

declaration of variable ignored in a sub-routine

Posted: Tue Aug 18, 2009 8:46 pm
by azarus
It seems that the fonction dim work only the first time in a sub-routine:
A exemple:
object myform as form
     Height=100
     Width=100
     object click as button
onclick=cluk
end object      
end object
myform.ShowModal
sub cluk()
dim i as double
showmessage "i= "+str$(i)
if i< 1 then dim a as double
showmessage "a= "+str$(a)
i=1
end sub

If I click the first time I obtain:i=0 and a=0
the second time I expect i=0 but I obtain 1 and with the variable a I expect a bug because it`s not declared but I obtain a=0
I think that dim is ignored the second time.

declaration of variable ignored in a sub-routine

Posted: Wed Aug 19, 2009 7:34 am
by PaPi
Hi,
Not "dim is ignored the second time", but the variables in the subroutines (and functions) keeps the own values on all further callings, I wish so.
PaPi

declaration of variable ignored in a sub-routine

Posted: Thu Aug 20, 2009 10:53 am
by fred
See also the example in ProjectsExamplessort.bas, it has this comment:
``fnx basic does not keeps a stack for local varibles
``these are global for recursive calls

declaration of variable ignored in a sub-routine

Posted: Fri Aug 21, 2009 6:40 am
by PaPi
In my opinion your code wokr freely! You can make the little modification:
.
.
.
if i< 1 then
dim a as double
showmessage "i=0 ???  " + "i= "+str$(i)
end if
.
.
.
and you can see.
PaPi