AI Assisted VB6 Development: Compiling, Testing and Debugging with an Agent

David Zimmer · Sandsprite 2026

In this paper we cover how to put an AI coding agent to work on Visual Basic 6 code: how it compiles, how it tests, how it debugs, and how it can drive a live VB6 GUI to get real feedback and timing data while the program runs.

Everything here came out of real work sessions and is distilled into a companion package, vbai_compile_help. The package is written for the AI. It is the playbook you hand the agent at the start of a session, and it holds the gory details, the scripts and working templates. This paper is the human introduction: what the package is, why it is needed, and some of the best techniques we found along the way.

Download: vbai_compile_help.zip  (playbook, compile wrapper, templates, gotchas, ROT GUI driving kit, C DLL guide and test harness)
In this paper
  1. Background
  2. What is in the package
  3. The compile loop
  4. Testing a language with no console
  5. Driving a live GUI over the ROT
  6. Case study: a filtering ListView
  7. VB6 language traps
  8. Calling your own C code
  9. Conclusion

Background

I still maintain a lot of VB6 code. Tools like VBDec, SysAnalyzer and the IDA JScript projects all have VB6 at their core, and they share components that have drifted apart over the years as each project tweaked its own copy.

Modern AI coding agents are very good at reading and writing code. Out of the box, though, they are terrible at VB6. Not because they can't write the language, but because everything around the language is hostile to the way an agent works:

Without help, an agent burns hours rediscovering all of this, and it does so again in every new session because it has no memory of last time. The fix is simple: write down what we learn, in a form the agent reads first. The package is that document, plus the tools that make the rules automatic.

How we got here

This is the third step in a progression. Earlier this year I wrote up my first big AI coding projects, a JavaScript engine and a Scintilla wrapper both written in VB6 (Quick post on AI coding). That was all done in a chat window. I was the compiler, the test runner and the memory. I pasted code into the IDE, ran it, and pasted the errors and debug output back. One lesson from that post sticks out here: the model has weaknesses that produce repeatable classes of bugs, and you have to warn it about them. In chat that meant repeating myself in every new context.

The second step was letting Claude Code loose on VB6 directly, in a virtual machine, running as admin with permission prompts turned off. It found its own way to compile, read build errors, run unit tests, check debug logs and circle back to fix the code, even checking results against PowerShell or Python versions of the same logic. At the end of that session I had it write out everything it had learned as a set of notes a fresh session could load on startup (VB6 AI Compile Debug). That was the first version of vbai_compile_help.

Since then every session has added to it: the console harness, exact error line mapping, differential testing, the live GUI driving kit, and the language traps. The warnings I used to retype in every chat are now a folder the agent reads first.

A word on safety: an agent that can compile and run code can also do anything else on the machine. Running elevated with prompts turned off is fine in a throwaway VM. Think hard before doing the same on a box you care about.

What is in the package

ItemPurpose
README.mdStart here. The rules that save hours, the workflow that works, and a map of the rest.
VB6_compile_and_test_notes.mdThe deep reference: command-line builds, .vbp templates, the elevation wall, reading errors, headless harnesses, differential testing.
tools/vbmake.ps1Compile wrapper. Normalizes encodings, runs /make, parses the log and prints the real offending source line.
templates/Minimal .vbp files and harnesses that compile first time (Sub Main and form based).
gotchas/Standalone write-ups of the landmines, including the language traps in this paper and a harness that proves each one.
ui_driving/The kit for driving a live VB6 GUI over the Running Object Table: the remote scripting class, a PowerShell client, a host template and a full worked example.
examples/Real working reference code (a SQLite data layer) to show the agent house style.
C_DLL_integration.mdVB6 plus your own C DLL: building x86 stdcall exports, the Declare type mapping, strings, Variants, arrays, structs and callbacks, what each runtime error means, and API design patterns from real projects (script engines, debuggers, cross-process control).
c_dll_harness/A C DLL and a VB6 console harness that test every rule in that guide, including leak checks, with the recorded results.

Usage is just as simple. Drop the folder somewhere the agent can see it, and start the session with "first learn how to compile VB6 from vbai_compile_help". From then on the agent compiles, tests and debugs on its own.

The compile loop

The VB6 IDE has a perfectly usable command-line build mode. The trick is using it in a way that never blocks:

VB6.EXE /make "proj.vbp" /out "err.txt" /outdir "somedir"

/out is the important part. It sends compile errors to a text file instead of a dialog. The exit code is unreliable, so success means the binary exists and the log says succeeded. /d NAME=1 sets conditional compilation constants, which becomes very handy later.

Rule one: it's the line endings

VB6 source files must be CRLF and ANSI (Windows-1252) with no byte order mark. Write a class with LF endings and VB6 refuses it with 'X.cls' could not be loaded, and nothing else. This was by far the largest single time sink, so the wrapper script normalizes every file in the project before each build. We even made it the package's closing line: when in doubt, it's the line endings.

The elevation wall

Projects that reference OCX controls (mscomctl and friends) fail command-line builds with Error accessing the system registry unless VB6 runs elevated. Projects that only reference stdole2.tlb build fine without elevation. In practice I just run the agent session elevated on my dev box. For pure logic testing the package uses tiny stdole-only harnesses that dodge the issue entirely.

One wrinkle: on Vista and later the VB6 IDE should be set to Windows XP compatibility mode so it gets the registry access it expects. Once it is, Windows will not start VB6.EXE at all from a non-elevated shell ("requires elevation"), not even for a stdole-only harness. With that setup, plan on an elevated session for every build.

Errors lie, but predictably

The line number in VB's error log is not the physical line in the file. It counts from the first Option statement and skips hidden Attribute lines. Once we calibrated that across .bas, .cls and .frm files, the wrapper could print the real line with a >> marker and some context. That one change turned "Syntax error, Line 212" into something an agent can fix on the first try.

Occasionally the error blames an innocent line in a different module. That is usually a genuine error in a referenced class combined with VB's lazy class compilation. The fix is the same as it has always been: bisect. Stub the suspect class, rebuild, add members back until it breaks.

BUILD FAILED
----- raw /make log -----
Compile Error in File '...\modTraps.bas', Line 9 : Syntax error
Build of 'traps.exe' failed.

----- modTraps.bas -----
message : Syntax error
vb line 9  ->  physical line 11
       9:     For i = 0 To n
      10:         t = Trim$(parts(i))
>>    11:         If t = Then
      12:             cnt = cnt + 1
      13:         End If

Note how VB says line 9 while the real problem is on line 11.

Testing a language with no console

A compiled VB6 exe can't print. There are three ways around it, and the package has templates for each:

Most bugs never need a debugger. A global gLog flag gating a one-line file logger, sprinkled generously, localizes the vast majority of problems to a procedure and some values. Only then do you number the lines of that one procedure and read Erl. No add-ins required.

For a rewrite of anything that matters, we use A/B differential testing. Build the old version and the new version, run both over the same real data, and diff the outputs. Identical output means safe to swap. Any difference points straight at the divergence. The rigor should match the stakes: a clean compile is fine for glue code, while a parser you are about to retire deserves unit tests, a differential run and a benchmark.

Driving a live GUI over the ROT

Logic harnesses only go so far. Questions like "why does typing in this box lag at 20,000 rows" need the real control, in a real form, receiving real keystrokes, with timing measured from inside the process.

For this we reused an idea from a previous paper, Scripting the Disassembler: register an object in the Running Object Table so any external script can grab it with a late-bound call and talk to the live program.

 PowerShell (any bitness)                       VB6 exe (32 bit, STA)
 rot_client.ps1                                 frmHost (hosts the thing under test)
   GetObject("vbai.AppHost")  --- ROT ------>   CDriver (registered in the ROT)
   drv TypeText "abc" $true  --- IDispatch ->     SendMessage WM_CHAR -> real KeyPress path
                             <-- ms --------      QueryPerformanceCounter timing in process
   drv Items / Info / Dump   <-- strings ---      state readers

The host is a small exe that puts the control on a form and registers a CDriver class with CRemotelyScriptable. The driver exposes plain methods (load N rows, type this text, wait until idle, return the visible rows, return the last timing). From PowerShell the agent can poke the app, read the result and poke again, with no rebuild in between. It's an interactive debugger loop for the agent.

The lessons that made it reliable:

Case study: a filtering ListView

ucFilterList is a ListView usercontrol with a filter textbox on top. I have used it in most of my VB6 tools for about ten years, and every project had its own slightly different copy. It was the first real target for the ROT harness. Ten years of use, and the quadratic bug below was in there the whole time. I did notice the occasional slow filter, but rarely enough that it was never worth hunting down.

The first thing the agent did was a scaling probe: time the same filter at 500, 1k, 2k and 4k rows. Doubling the rows quadrupled the time. Quadratic. The cause turned out to be one innocent looking helper call inside the per-row loop that grew the search term array by one element per row, so row k scanned k copies of the same term. One early "hang" turned out to be 603 seconds of CPU time and a 2 GB working set. It wasn't stuck, just slow.

From there the agent rebuilt the filter engine: parse the filter once instead of per row, lowercase each row once and compare binary, suspend redraw and sorting during bulk fills, pump DoEvents on a time budget with a generation counter to survive reentrancy, and choose between live filtering and a debounce based on a learned cost model rather than a fixed row count. Profiling builds used #If FL_PROFILE blocks, which cost nothing in normal builds, and showed exactly where the time went. The thing I was ready to rip out to save time (row colors) cost 0.3 µs per row and stayed.

Operation (10,000 rows)BeforeAfter
Single term filter~30 s14 ms
Clearing the filter~420 ms8 ms

At 50,000 rows a broad filter now takes under two seconds, and the remaining cost is MSCOMCTL copying rows into the list, not the search.

Correctness was checked with an A/B differential: the original control was rebuilt straight from git into a second test exe with the same driver, and both ran the same inputs. That caught a real hex parsing regression that hand testing had missed. It also proved my own expectations wrong twice, which is the point. Let the differential decide.

The resync

The last step was the one I had been putting off for years. I never moved this control into a shared OCX. I like being able to tweak a copy for one project without affecting anything else. The price is drift. Over ten years each project's copy had picked up its own features and fixes: VBDec added empty-cell filters and hex totals, SysAnalyzer added padded text exports, Yara WorkBench added icon filters and tooltips, the IDA JScript and ida_compare copies added copy helpers, update locking and a switch for number padding, and a few copies even changed what ListItems returns while a filter is showing. Every once in a while a big resync was due, and it was exactly the kind of job nobody wants: half a dozen copies of a 1,600-line control, each slightly different, with no history of who changed what or why.

This is where the agent really shines. It can hold every fork in view at once, diff each one against the others, work out which differences are real features and which are just the IDE changing the case of names, and port each feature into one master copy. When two projects genuinely disagreed on behavior, the difference went behind an opt-in property that defaults to the common behavior (IncludeHex, PadNumbers, ListItemsFollowsFilter), and a note at the top of the control records which projects expect which setting. Realistically I would never have done this sync by hand to this level of detail.

Proving it was a true drop-in was the same discipline as everything else. Each consuming project was copied to a scratch folder, built unmodified as a baseline, then rebuilt with the master control swapped in. All of them compiled with no consumer code changes, and no real project tree was ever touched. Each new feature also got PASS/FAIL checks in the ROT harness, so the merge is tested, not just compiled.

VB6 language traps

These compile clean and read correctly to anyone used to a modern language. They are exactly the mistakes an AI makes, because nearly everything it learned from short circuits. Every result below was verified by compiling and running a harness that is included in the package (gotchas/language_traps_harness), so you can rerun the proof yourself.

IIf always evaluates both sides

IIf is a function, not an operator. Both arguments are evaluated before the call, so it can never be used as a guard:

v = IIf(True, 1, Side())                 ' Side() still runs
s = IIf(o Is Nothing, "none", o.Count)   ' error 91 when o Is Nothing

And / Or never short circuit

VB6 has no AndAlso or OrElse. Every operand is evaluated:

If Not o Is Nothing And o.Count > 0 Then   ' error 91 when o Is Nothing
If o Is Nothing Or o.Count = 0 Then        ' error 91 when o Is Nothing

Nest the tests instead, or use Select Case True, which does stop at the first matching case.

And / Or / Not are bitwise

True is -1, all bits set, so logic works on real Booleans. Hand it numbers and you get bit math:

If InStr(s, "a") And InStr(s, "b") Then    ' 1 And 2 = 0: False, though both were found
If Not InStr("abc", "b") Then              ' Not 2 = -3: True, though it WAS found
x = 1: If x = True Then                    ' False, True is -1

An error in a condition under Resume Next runs the True branch

This one surprised even me. When the condition itself raises an error, "resume next" continues at the next statement, which is the body of the If. We confirmed it for block If, one-line If/Else and Do While:

On Error Resume Next
If o.Count > 0 Then        ' o Is Nothing: error 91...
    DeleteEverything       ' ...and this runs
End If

Keep Resume Next scopes to a single risky statement and check Err.Number immediately.

The rest of the short list

The package's gotchas/language-traps.md has the full list with fixes. Have the agent read it before it writes any VB6 logic. It is much cheaper than finding these one bug at a time.

Calling your own C code

A lot of my VB6 work leans on C: helper DLLs, embedded script engines, debuggers, plugins in other processes. This is where an agent is most confidently wrong. A Declare compiles no matter what you put in it, and the mistakes show up later as a wrong value, a leak or a dead process. So the package now has C_DLL_integration.md, which covers building the DLL, mapping every type, and the patterns I use for larger projects, plus a harness that checks the rules instead of trusting them.

The harness is a C DLL with one export per case and a VB6 console program that calls each one and prints what actually happened. Running it turned up some things I had wrong or had never pinned down:

Every recipe in the guide was also leak checked: 200,000 calls each against a function that deliberately leaks one string per call (+18 MB). All of them stayed flat.

It was also a good example of the agent working around a real machine. My box had the compiler but no Windows SDK headers or C runtime libraries, so it built the test DLL against an old SDK with no C runtime at all, and wrote down how in case the next session needs it.

The human version of all this, with more background, is on the site: Writing C DLLs for use with VB to get started, then the VB6 and C interop notes.

Conclusion

With a small amount of scaffolding, an AI agent becomes a genuinely productive VB6 developer: it compiles, tests, profiles and fixes on its own, and it can drive a running GUI to answer questions that used to need a human at the keyboard. What made the difference was not cleverness but writing everything down where the agent would read it, and turning each rule into a tool that applies it automatically.

For a brief recap:

The package is a living document. Every session that hits a new snag ends with a note added to it, so the next session starts smarter than the last. It turns out to be a good discipline for humans too.

Download: vbai_compile_help.zip