[Gambas-user] Migrating to Gambas

Benoît Minisini g4mba5 at gmail.com
Wed Jun 9 14:04:47 CEST 2021

Le 09/06/2021 à 06:05, John Anderson a écrit :
> On 6/8/2021 4:16 PM, John Dovey wrote:
>> Does anyone have any thoughts/advice about migrating a project from 
>> vb6 to Gambas?
>> I found a reference to an old project for migrating some forms, but 
>> that was for an old version of Gambas.
>> John
> Doing a VB6 to Gambas conversion now on large codebase.  New-ish user 
> here but it gets easier quick.
> Actually, I'm getting good results on a large project where we want to 
> keep source code as close to original as possible. Thanks to advice from 
> kind people here and just trying different methods out.
> In my case - Starting "from scratch" is 100% bullshit in terms of labor 
> time if it can be avoided on a large system; in our case it could be 
> years testing something we started from ground zero.  We especially have 
> to keep the critical state machine routines intact, exactly as they are, 
> and without any errors introduced - that source code has millions of 
> hours verified and expensive testing.  If you're the one paying the 
> bills and running a business, you want to re-use existing source code 
> where it makes sense to do so.  Not all the time, but be practical about 
> your approach.  Sometimes you might start from scratch.  Other times 
> that is the very last thing you want to do.
> So far we have been able to re-create a lot of the most critical state 
> machine code pretty well now that we can declare a Static var inside a 
> state machine.  That completely changes things, and for the better...IF 
> you're doing a VB conversion.
> We have converted several forms already, trying different methods.  It 
> tuns out it doesn't take too long to print out the form on VB6, jot down 
> the control names for each control, and then duplicate the equivalent 
> layout in Gambas with the same or close equivalent control.  It helps to 
> run VB6 on a Windows VM in one monitor, and Gambas on another, so you 
> can get the layouts and control names the same.
> After that I made a wrapper for VB6 MsgBox to something like 
> Message.Info etc. on Gambas - gotta use Qt for that, according to docs 
> (we are).  Because we used MsgBox hundreds of times.  We can clean that 
> up later but for now wherever we can make a wrapper for your simpler VB 
> calls that don't exist in Gambas, or the maybe function exists but goes 
> by a different name.
> Convert "Double" vars to "Float".    Watch out on your C-code function 
> call test suites here, if your test procedure thinks a struct has a 
> float instead of a double....it might flag a struct mismatch for a 
> C-call until you change your code review procedures.
> Handle Globals a little different, we use the "Put globals in 
> Globals.mod" file method as suggested in docs.
> Your Find / Replace tools works very close to how it works in in VB6.
> The real bummer is converting arrays to square brackets.  We will have 
> to do that in many many thousands of places.  I'm toying with the idea 
> of scanning the code base for all arrays, and using that list to search 
> for where those arrays are used in code...automation might help here.
> Watch out for your class Getters and Setters - in VB6 look for Property 
> Let, Get, Set and convert that to Property _Read, _Write, and ??? in 
> Gambas.  In Property Declarations section of help file.  I haven't 
> needed to convert a Property Set yet, but in VB6 that was a property 
> object that could -only- be used on left side of an expression... I'm 
> not sure if I need to do that in my conversion yet.
> There is a gb.vb component that makes some string funcs, dates, rounding 
> etc working like VB6.
> There are SOME spots that yes, will require rewrite.  But I'm finding 
> that probably 85% of expensive source code is re-useable pretty much as is.
> At least that's what we're finding out so far.  Some weeks of work ahead 
> of us, but early testing is looking hopeful.
> -John

It reminds me two important horrors in VB that you must be aware of:

1) You have to use 'Set ...' to set an object reference. Otherwise, it 
assumes that you are assigning a (random ?) property of the object.

So "A = B" must not become "A = B" in Gambas if A is an object reference.

2) Every function argument is passed by reference by default! I think 
this is the most stupid thing I have ever seen in a language, leading, 
for unaware programmers, to countless bugs.

So, when you translate VB code, you have to check every function to be 
sure that it does not assign its arguments, and then change the value 
located in the calling function.

If this is the expected behaviour, then you have to add the "ByRef" 
keyword in Gambas, both in the function declaration and in the function 
call (see the documentation on ByRef).


Benoît Minisini

More information about the User mailing list