Skip to content

takshil6/vb6-to-python-migrator

Repository files navigation

VB6-to-Python Migration Tool

A Python 3 desktop tool for migrating Visual Basic 6 codebases to Python 3, with a Tkinter GUI, CLI batch mode, regression testing framework, and SQLite-backed migration logging.

Python License Tests


Features

  • Dual interface — Tkinter GUI for interactive use, CLI for batch processing
  • Handles 15+ VB6 language constructs — variables, loops, conditionals, functions, file I/O, error handling, user-defined types, and more
  • Side-by-side preview — VB6 source and Python 3 output rendered in real time in the GUI
  • Regression testing framework — 59 test cases verifying output correctness per construct
  • SQLite-backed logging — persistent migration status and test results stored in results.db
  • Deterministic output — same input always produces the same output
  • Nothing silently dropped — unknown constructs are preserved as # [VB6] ... comments

Tech Stack

Component Technology
Language Python 3.10+
GUI Tkinter (stdlib)
CLI Parsing argparse (stdlib)
Database SQLite3 (stdlib)
Testing pytest
Parser Regex-based line-by-line lexer

Installation

git clone https://github.com/takshil6/vb6-to-python-migrator.git
cd vb6-to-python-migrator
pip install -r requirements.txt

Usage

GUI Mode

python main.py

Opens the Tkinter desktop application. Select .bas files or a directory, preview VB6 source and generated Python side-by-side, then click Convert to write .py files to the output directory.

CLI Mode

python main.py --cli --input samples/ --output output/ --verbose --summary
Flag Description
--input DIR_OR_FILE .bas file or directory to process (required)
--output DIR Output directory for .py files (default: output/)
--verbose Print per-file status to stdout
--summary Print a migration summary table at the end
--dry-run Preview output without writing any files
--no-log Skip writing results to results.db

Run Tests

pytest tests/ -v

Supported VB6 Constructs

Construct VB6 Example Python 3 Output
Variable Declaration Dim x As Integer x: int = 0
Constants Const PI = 3.14 PI = 3.14
If/ElseIf/Else If x > 0 Then if x > 0:
For Loop For i = 1 To 10 for i in range(1, 11):
Do While Do While x < 10 while x < 10:
Select Case Select Case x match x:
Sub/Function Sub MySub() def my_sub():
Arrays Dim arr(10) As Integer arr = [0] * 11
String Functions Mid(s, 2, 3) s[1:4]
File I/O Open "f" For Output As #1 f = open("f", "w")
MsgBox/InputBox MsgBox "Hello" print("Hello")
Error Handling On Error GoTo handler try/except block
User-Defined Types Type MyType @dataclass
Math Operations Sqr(x) math.sqrt(x)
Comments ' comment # comment

Project Structure

vb6-to-python-migrator/
├── main.py               # Entry point — routes --gui and --cli modes
├── requirements.txt      # External dependencies (pytest only)
├── LICENSE
├── README.md
├── .gitignore
├── src/
│   ├── __init__.py
│   ├── parser.py         # VB6 lexer/parser — tokenizes .bas source into AST nodes
│   ├── converter.py      # AST-to-Python code generation
│   ├── db.py             # SQLite schema, logging, and summary queries
│   ├── gui.py            # Tkinter GUI application
│   └── cli.py            # CLI batch processing logic
├── samples/              # 15 reference VB6 .bas files (one per construct)
│   ├── hello.bas
│   ├── variables.bas
│   ├── conditionals.bas
│   └── ...
├── output/               # Generated Python files (gitignored)
└── tests/                # pytest regression test suite (59 cases)
    ├── conftest.py
    ├── test_converter.py
    └── test_constructs.py

Limitations

  • Syntax-level migrator, not a full compiler — semantics are approximated, not guaranteed
  • Complex VB6 patterns (COM objects, Windows API calls, VB6 Forms/UI controls) require manual review
  • Output is a strong first draft — review before production use
  • Tested on standalone .bas modules; full VB6 projects with multiple interdependent files may need post-processing
  • & concatenation converts to + without str() wrapping — may fail at runtime when mixing types

Contributing

Contributions welcome. Fork the repo, create a feature branch, and open a PR.

Run pytest tests/ -v before submitting to ensure all tests pass.


License

MIT License — see LICENSE for details.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages