[Gambas-user] Keep variable value between subroutine calls?
Benoît Minisini
gambas at ...1...
Mon Aug 24 00:09:19 CEST 2009
> I'm having trouble getting my mind around how to do something in Gambas,
> and I'm hoping that someone can explain (or even better, show) how to do
> it.
>
> As part of an application I'm trying to write, I need to be able to
> change a variable in a subroutine and still have the value available the
> next time the subroutine is called. I _used_ to think that this was
> called a "static" variable, but now I'm not so sure any more :-)
>
> How can I keep the value of a variable intact between calls to the same
> subroutine?
>
> sub Routine()
> V as integer
>
> select case V
> case 0
> V = 3
> case 1
> V = 2
> case 2
> V = 0
> case 3
> V = 1
> case else
> V = 0
> end select
>
> end
>
> Each time I call the subroutine, I want it to "remember" what "V" was.
> How?
>
> DMerriman
You must declare your static variable globally, as you cannot do that locally
in Gambas.
Regards,
--
Benoît
More information about the User
mailing list