Table of Contents

Importing VB6 forms

Ce document est disponible en français

VB6FormReader reads the designer files of a Visual Basic 6.0 project into the form model: forms (.frm), user controls (.ctl) and property pages (.pag), with the companion binary files they cite (.frx, .ctx, .pgx). It reads only: nothing writes a designer file.

Reading

Method Reads
ReadFile(path, options) A designer file, and each companion file it cites, from the designer file's folder, the name compared without regard to case.
Read(text, companion, options) A designer file's text, and the bytes of its companion file, or none.

The text is decoded as Windows-1252 unless VB6ImportOptions.Encoding says otherwise.

A class of VB6's VB library reads as the RDForms class of the same name: Begin VB.TextBox Text1 is an RDForms.TextBox.

The project's own UserControls that a form places, such as Begin Project1.Gauge Gauge1, are read as components when VB6ImportOptions.Classes holds their classes: see UserControls. Without them, each one is kept as text.

ReadFile reads a companion only from the designer file's folder. A cited name that is a rooted path, such as a network path, is not read, and neither is a name that holds a NUL: each is reported as a missing companion.

The result

A read returns a VB6FormImport:

Member Holds
Form The form, or null when the file holds none.
ModuleText, ModuleLine The code after the designer half (its Attribute lines included), and the line it starts on.
UnmodelledHeader The header lines that name no control library the form lists, as they were read.
UnmodelledRoot A root block that is not a form's, kept as text.
Diagnostics What the import reports, in the order of the lines it is about.

What is kept, reported and left out

A read does not throw on what a file holds. It keeps what the model cannot hold as text, and reports it:

Diagnostic Severity What the reader does
NoDesignerBlock Error No form.
NotAFormRoot Error No form. The root block is kept as text (UnmodelledRoot), and the header lines are left out.
NamelessComponent Warning (Error for the root) The block is kept as text.
NestingTooDeep Warning A block nested deeper than 2,500 (MaxNestingDepth, the root included) is kept as text, with its contents.
MalformedLine Warning The line is left out.
UnbalancedBlock Warning A BeginProperty left open ends at the End of its block; a Begin left open ends with the file.
UnmatchedEnd Warning An EndProperty that closes nothing is left out.
InvalidValue Warning The property is kept as an UnmodelledProperty: a value it cannot hold, a number outside its type's range, or an Index that is not a number from 0 to 32767.
MissingCompanion, MissingRecord Warning The property stays at its default, and its citation is kept as an UnmodelledProperty.
MisplacedComponent Warning A component placed in one that cannot hold it is placed in the nearest enclosing container that can, at its written position; a control written inside a Timer is placed at the Timer's Left and Top added to its own instead, as VB6 places it.
UnmodelledClass Information The component is kept as an UnmodelledComponent, with its text.
UnreadLibraryReference, UnmodelledHeaderLine Information The header line is kept in UnmodelledHeader.

A property or a property bag the model does not have is kept as an UnmodelledProperty and not reported. The VERSION line is left out. A property a block sets twice has the value of its last line.

Positions and fonts

A file holds a control's position and size in twips, whatever its container's ScaleMode, and they are read as pixels, at 15 twips a pixel. The root's own position and size are its client area's, read the same way. A Line's ends are read as the file holds them, in its container's scale: twips, unless the container (a form, a UserControl, a PropertyPage or a PictureBox) has a ScaleMode of its own.

A control that writes no Font, on a form that writes one, takes a copy of the form's font.

Differences from VB6

The fixtures in the tests were built and run under VB6, and the tests assert what VB6 read from them.

Case VB6 reads The reader keeps
A user-scale Line's ends, written 0 0 100 50 -0.0124842 0 100.0125 50 The written values.
A form's ScaleWidth, written 8000 7995, its window's client width The written value. In the form's window, where its ScaleMode is a unit, it reads the client width (the scale).

ACCUEIL • HOME | BIENVENUE • WELCOME | DÉMARRER • GET STARTED | IMPORTER • IMPORT | CONTROLS | FORMAT | 🌐 rubberduckvba.ca