[Gambas-user] Correct strategy for VB static var conversion to Gambas?
John Anderson
johna at starflightinc.com
Mon May 31 05:56:37 CEST 2021
On 5/30/2021 6:37 AM, Brian G wrote:
> Given this example
>
> Function updateSales(ByVal thisSale As Decimal) As Decimal
> Static totalSales As Decimal = 0
> totalSales += thisSale
> Return totalSales
> End Function
>
> Being called as updateSales(777.77)
>
> If you create a new .mod file for each function/sub that contains static variables
> The mode file gets the name of the function/sub. Again in gambas sub/functions are just aliases of sub.
> eg
>
> updateSales.mod
>
> Then the code should end up looking like
>
> 'begin module
>
> private totalSales as float = 0 ' from decimal
>
> public sub _call(ByVal thisSale As float) as float ' from decimal
> totalSales += thisSale
> Return totalSales
> end
>
> 'end module
>
> You will not have to change or update the names of your functions/subs anywhwere else in your code.
> Simply reconstruct it into a module.
>
> _call is a special name in gambas that is executed when a module is called by name.
>
> So now your code does not need to change as far as calling the function.
> it still is called as
>
> updateSales(777.77)
>
> I am not sure how many separate modules gambas can support.
Thanks Brian - That's good info about _call, etc. and that could come in
handy other places as well. I had seen that in docs but I didn't make
the connection to my project until you showed it here.
-John
More information about the User
mailing list