[Gambas-user] Correct strategy for VB static var conversion to Gambas?
jussi.lahtinen at gmail.com
Sun May 30 21:39:47 CEST 2021
I have been a bit too busy to follow this very long thread. So just a
general note. I did convert a vb6 project with 50 000 lines of (ugly) code
into Gambas (2), when I started.
It wasn't as hard as I thought it would be. But your mileage may vary.
On Sat, May 29, 2021 at 10:48 PM John Anderson <johna at starflightinc.com>
> On converting larger codebase from VB6 to Gambas, I wanted to double
> check my method for converting "static" type variable module declares into
> the Gambas way. This might be obvious to everyone, but I just wanted to be
> sure. Or am I smoking the wrong stuff again?
> This is for module-type functions where only a single instance of the code
> function is used for the entire project. I'm not talking about static vars
> used in multiple-instance classes.
> From VB world: I'm talking about a static variable/object used in a
> sub/function that is only initialized when the function is first invoked,
> and is stored on a static heap for the project run session. The value of
> the variable persists every time the function is invoked every time after
> first use. The static var shall exist until the program exits. It
> absolutely can't be seen or used by anything outside of the function - ie.
> the scope of static var is at the function level only. In other words -
> it's just like a local variable that is initialized only once, and lives on
> the static heap instead of the stack.
> In Gambas World: It looks like you can't declare a variable of type
> static in module function, nor can you declare an array -inside- the module
> function. OK, I'll work according to those rules. I know that variable
> declares inside a Gambas module are inherently static in nature. If I'm
> reading docs right.
> I THINK the approach is to convert old VB existing functions with statics
> is to make a module file (of ModuleName.mod) for -each- function, and lay
> out generally as
> 'Gambas module file
> 'Static-like vars declared here
> Private myLVar As Long = 0
> Private myArray[20, 500] As Integer
> 'Function/ Sub below
> Public Function myFunc(Param1 As Integer, Param2 As Integer,...) As Boolean
> Dim x As Integer 'These are initialized at every function call
> Dim somevar As Byte 'Etc.
> 'Actual code goes here....
> myArray[Param1, Param2] = 42
> '... whatever
> Return True
> Now everywhere else in the project can use ModuleName.myFunc (Param1,
> Is that correct strategy or is there a better approach? Being static,
> will "static var" be able to be used with upcoming "Data Breakpoint" debug
> I guess doing it this way gets my wish of seeing long Subs / Funcs
> one-at-a-time in the IDE. I'll have over 1100 files in the source
> directory though. Ughh.
> If this is correct way, I see a way to make the conversion process
> sorta-kinda-automated with a VB6 to Gambas code converter tool - it won't
> be perfect but at least the module files can be generated one for each
> module function, and static vars placed in top module declaration section
> of each file - outside the function. There rest of code will have to be
> checked over and tweaked and tested. It's a start. Maybe. Maybe bad idea.
> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the User