We Are GAP Mobilize
Free Assessment Tool

Can ChatGPT modernize my VB6 app?

by John Browne, on Apr 25, 2023 4:18:54 PM

Can ChatGPT modernize my VB6 app?Generative AI--let's just call it ChatGPT for now--has arrived with the same level of enthusiasm as the good citizens of River City when Harold Hill showed up in town to pitch the idea of a marching band in The Music Man. Programmers are looking at it either with suspicion or with all the glee of a frat party discovering a hidden keg. And it almost goes without saying that those of us sitting on old but necessary legacy apps are wondering, hmm? Can this be the silver bullet? Can it migrate, say, VB6 to C# and .NET?

That would certainly save a lot of time, money, and bother. 

If it works. 

So, does it?

ChatGPT can write code, but is it good code?

Ask ChatGPT a question and the answer seems to pass the Turing test brilliantly. It's so human-like in its diction and style it's easy to anthropomorphize the "robot" on the other end of the chat. Code doesn't have a "style" per se, but asking ChatGPT and its related apps like Github Copilot and Auto-GPT to write code can be a real eye-opener. Unlike carbon-based developers, AI systems don't need to look up obscure parameters and syntactical details in Stackoverflow or Microsoft docs, they know all already. 

But as this very detailed and interesting post from Stephen Wolfram points out, there's no creativity behind the curtain, any more than there was with the Wizard of Oz. 


The real "magic" behind generative AI, as Wolfram shows, is its ability to accurately predict the next word in a phrase, or the next term in a line of code. That prediction is based on a deep ML model of what already exists that it has had access to. In the case of Github Copilot, that's at least the entirety of all the public repos in github (I don't  know if private repos were used for the learning model).

Let's think about the problem of using generative AI to modernize a really old legacy application--one written in VB6.

We (Mobilize.Net) of course, wrote the first (and best) tool to solve that problem, funded by Microsoft and included by them in the original Visual Studio .NET version and several versions following. Microsoft at the time of the .NET introduction had a vested interested in keeping the enormous numbers of VB6 developers in the Microsoft developer ecosystem, and specifically helping them make the leap to .NET.

That was over 20 years ago and we've improved and refined the product constantly, where today it is the most used tool for modernizing VB6 in the world. 

Both us and our customers routinely modernize very large and complex VB6 code bases to .NET and even to the web. And by large I mean in excess of 1MM LOC.

What ChatGPT can do for VB6

We've played around with it, testing its ability to convert VB6 to C# and the .NET framework (with Windows Forms). 

It's not bad, actually. 

Here's a tiny example. First the VB6 code snippet:

VB6 sample before migrating to C# with ChatrGPT

Pretty standard and familiar stuff: use On Error GoTo to wrap a subroutine for error handling, open an ADODB database connection using a recordset object. You could find something similar in literally millions of VB6 apps.

Here's the C# version ChatGPT created: 

C# version after migrating from VB6 with ChatGPT

Some interesting things here: the inclusion of the comments, the class name pulled from a string literal in the VB6 program, the use of record set. Also less interesting is that it didn't update from ADODB to ADO.NET for the DB access model. That's something any intelligent human developer would do naturally.

A lot of the code conversion is super straightforward, eg Debug.Print to Console.Writeline isn't rocket surgery. 

What ChatGPT can't do for VB6

The above example shows that the AI system is useful if not brilliant in migrating a small VB6 sample to C#. What about a bigger problem/program? 

Our canonical sample program is Salmon King Seafood (you can find it on github here).  It's not huge--under 9KLOC of pretty straightforward VB6. But trying to migrate it with ChatGPT was a big fail. The AI doesn't understand the idea of a VB project (with multiple related files), nor is there a way to provide context of the code. Big files can't be loaded in entirety. And so on. 

Going back to Wolfram, it seems likely that ChatGPT converts the VB6 line by line, token by token. By contrast, the Visual Basic Upgrade Companion loads an entire application context--including all code and references--and builds a complete abstract syntax tree representing the entire app. That AST is the basis for the code generator, given that it can use the context in the AST to create meaningful--and "better"--output code patterns. It also lets you--the developer--choose among options for migration, such as moving from ADODB to ADO.NET. 

What should you do?

My recommendation is use ChatGPT (or similar) for simple, tiny VB6 apps as an alternative from rewriting them from scratch. Of course, you won't really get any decent refactoring done by the AI engine. But it's a start.

For anything large or complex, you are still faced with the choice of leaving it alone (ugh), rewriting from scratch (GLWT), or using a tool like VBUC to automate the migration, slashing risk, time and cost to get a newer code base into production where you can begin the ongoing task of refactoring and improving. 

In the meantime, let me hear about your experience with these tools. Drop a comment below or email me.  

Topics:application migrationVBUCChatGPT


Subscribe to Mobilize.Net Blog