VB6Parse / Documentation / Getting Started

Step-by-step tutorial for parsing Visual Basic 6 code

Introduction

This guide will walk you through using VB6Parse, from installation to advanced parsing scenarios. By the end, you'll understand how to parse VB6 projects, handle errors, navigate syntax trees, and build tools that process legacy Visual Basic 6 code.

Prerequisites

Installation

1

Create a new Rust project

cargo new vb6parse-demo
cd vb6parse-demo
2

Add VB6Parse to Cargo.toml

[dependencies]
vb6parse = "0.5.1"
3

Verify installation

cargo build

Your First Parse: Hello World

Let's start with the simplest possible example - parsing a VB6 module with a single subroutine.

1

Create a simple module parser

Replace the contents of src/main.rs:

Loading example from GitHub...
2

Run the example

cargo run
💡 Key Concept: ParseResult
VB6Parse uses a ParseResult<T, E> type that contains both the parsed output (Option<T>) and any failures (Vec<ErrorDetails<E>>). This allows partial success - you can get a usable parse tree even if some parts failed.

Parsing VB6 Projects

VB6 projects (.vbp files) list all modules, forms, and references. Let's parse one:

Loading example from GitHub...
⚠️ Important: ProjectFile only parses the .vbp file itself - it doesn't load the referenced files. You'll need to read and parse each module/form/class file separately.

Handling Parse Errors

VB6Parse is designed to handle malformed input gracefully. Even with syntax errors, you often get partial results:

Loading example from GitHub...
💡 Best Practice: Always check both the result and failures. In tools that process many files, log failures but continue processing - don't stop on the first error.

Tokenization

For lower-level analysis, you can tokenize VB6 code without building a full parse tree:

Loading example from GitHub...

Navigating the Concrete Syntax Tree

The CST preserves all source information including whitespace and comments, making it perfect for code analysis tools:

Loading example from GitHub...

Parsing Forms and Controls

Forms are the most complex VB6 file type, containing both UI controls and code:

Loading example from GitHub...

Common Use Cases

Here are some practical applications you can build with VB6Parse:

Code Migration Tools

Parse VB6 projects and convert them to modern languages (C#, VB.NET, Python). Extract forms, business logic, and database connections for automated conversion.

Static Analysis

Build linters and code quality tools for legacy VB6 codebases. Find deprecated API usage, detect code smells, enforce coding standards.

Documentation Generation

Automatically generate API documentation from VB6 source code. Extract function signatures, comments, and module relationships.

Code Metrics

Calculate lines of code, cyclomatic complexity, dependency graphs, and other metrics for project planning and technical debt assessment.

Form Extraction

Extract UI layouts and control hierarchies from .frm files for migration to modern UI frameworks or for visual documentation.

Code Search Tools

Build semantic search tools that understand VB6 syntax. Find all usages of a function, locate API calls, track variable usage across projects.

Next Steps

Now that you understand the basics, explore these resources:

💡 Need Help?
• Check the GitHub Issues for common problems
• Review the examples directory for more code samples
• Open a discussion or issue if you encounter problems