declaration of variable ignored in a sub-routine

Here one can report bugs or hold discussions about bugs updates and work arounds.
Post Reply
azarus
Posts: 5
Joined: Tue Nov 08, 2005 3:00 pm

declaration of variable ignored in a sub-routine

Post: # 495Post azarus
Tue Aug 18, 2009 8:46 pm

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.

PaPi
Posts: 114
Joined: Wed May 16, 2007 11:55 am

declaration of variable ignored in a sub-routine

Post: # 496Post PaPi
Wed Aug 19, 2009 7:34 am

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

fred
Posts: 54
Joined: Thu Apr 23, 2009 10:08 am

declaration of variable ignored in a sub-routine

Post: # 497Post fred
Thu Aug 20, 2009 10:53 am

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

PaPi
Posts: 114
Joined: Wed May 16, 2007 11:55 am

declaration of variable ignored in a sub-routine

Post: # 498Post PaPi
Fri Aug 21, 2009 6:40 am

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

Post Reply