Visual Basic and RealBasic - Compatible?
These notes were written while attempting to move a simple VB 6.0 application to RealBasic 4.5. The experience was not pleasant (although new versions have since come along, and Real Software does hope to attract VB people).
Since I wrote this page in August 2002, I have paid no attention to RB, choosing instead to rewrite in C++. However I received a note from a gentleman at Real Software with details of some 'features' which they have now dealt with. So it sounds as if they are making progress in this area. Full compatibility can never be expected -- if only because the VB6 toolset is so huge.
1. Call functionname not supported (RB 4.5, 5.0 only -- fixed in 5.5)
RB does not support this (although I gather it will in 5.5). It is, of course, not trivial to change in an existing application. Worse, there is a 'gotcha' lying in wait. If you just omit the 'call', VB compiles. However, it silently behaves as if every ByRef was a ByVal in the called Sub or Function, but without changing the code, or giving any compilation errors. This means that any values returned that way will be lost. My solution for some very frequently called sub's was to create a dummy return code, and treat all these subs as functions.
Call MySub
became
dim dummyrc as integerdummyrc = MySub
Of course the Sub's then complain, since they don't have a return value, but this may be quicker than amending all the Call statements - depends on the code.
2. Goto not supported
Just as well, really. Except, how do you do error-handling in a VB sub? Yes, that's right - with an On Error Goto errorhandler. Crummy, but there you are. Well, RB does not support this method of doing things. Their solution is undoubtedly more elegant: but VB people aren't buying RB for elegance.
Instead you need an "exception" statement at the top of the error handler, as in Ada and PL/SQL.
What I've done is add this as a comment in my code in VB, to facilitate portability.
'--Exception err Errorhandler: [error code]
VBCleaner comments out the On Error and the errorhandler: label anyway, and then all I have to do is a global change to remove the leading marks.
The 'err' bit creates an object like our err object - otherwise it's undefined. See below for more on err.
3. 'Exit Sub / Exit Function' notes
These change, of course, to 'Return'. The VBCleaner utility (now VB Project Converter, and integrated in RB) will do this for you; but don't try to do it anyway in VB - it's a different keyword in VB.
4. Modules
The section on VB at the back of the Developer's Guide omits to mention these. However these can be imported also. One misleading thing - VBCleaner can open a VBP project file, but it only processes the forms - the modules are not processed. However they can be processed in the same way as the .frm, by simply dragging and dropping onto the VBCleaner.
Once converted, both .frm and .bas are dragged onto the project window. The new Window will appear immediately. Don't be alarmed if the Modules are simply numbered, and seem to have no methods - it only means you have forgotten to click on the arrow to display the list! (Been there).
VBCleaner runs on OS9, which can be alarming if you're not expecting it!
Interestingly, if you open a new project in RB and drag in a bunch of converted files, RB can simply crash. Rather awkward, when it's the main form! I deleted the form and recreated it by running VBCleaner on the VBP, which created a new frm (originally, I'd just dragged the frm onto VBCleaner).
5. Arrays and Redim (4.5, 5.0 - fixed in 5.5)
If you have global arrays declared like this:
public myarray() as myUDT
for later redim, this is not permitted. The array will have to be a property, and must have an extent. However the extent can be -1, which means empty. Note that you can also use array.append method to add to an array size.
6. User-defined types
Not allowed, of course - far too simple! - RB want you to use a class instead. One more thing to learn which you'd rather not... and where, oh where in the Developer's Guide Index is 'class' to be found?
In fact it's just another thing to add to the Project Window, and the fields are the properties.
7. Err and error handling
The global object err wasn't available in RB 4.5 (but is now available).
Prior to this, you can mimick it with 'exception err'. 'err' will then be an object of class RuntimeExceptionClass. This has one property, Message, (rather than Description). So err.number will have to go, err.description -> err.message. err.raise is just replaced by raise.
Constructive feedback is welcomed to Roger Pearse.
Minor revisions, 18th December 2003.
This page has been online since 26th August 2002.
Return to Roger Pearse's Pages