Skip to content

Ref Scan

Benjamin edited this page Mar 25, 2022 · 5 revisions

Ref Scan

A quick reference scan is necessary to ensure improved conversion.

why Refscan?

Refscan is a way for the conversion process to help improve the conversion of certain expressions which may be converted.

Inherent Ambiguity in VB6

Consider the following snippet in VB6:

  Value = Reference

Many ways to interpret.

Reference may be one of several things:

  • A local Variable or Constant
  • A local Function
  • A Control on the current form (which would then provide the default property since Set isn't used).
  • A Public Variable or Constant in another module
  • A Public Function in another module
  • A Publicly available Enum (local or global)
  • A Form (which would then provide the default property for a Form -- .Caption).
  • etc

While the above code covers all of the above in VB6, C# requires parenthesis for function calls (and module name for calls to modules that haven't explicitly been referenced via using). Additionally, if the Reference is a control, the default property must be appended to the reference (in most cases) which must in turn be based on the control type (another lookup in the ref list).

In the case of remote functions, parenthesis would be required. In the case of variables or other objects, they are not. This conversion is important for the translating to correct C# code and decreasing the amount of manual intervention afterwards.

A few ways to convert

Possible Conversions are:

  • For functions: Value = Reference()
  • For enums: Value = EnumName.Reference
  • For controls (local or referenced): Value = Reference.DefaultProperty // < -- Well-known DefaultProperty names can be configured in the modControlProperties.bas module.
  • For most others: Value = Reference

So, while most of VB6 can be converted without any knowledge of the larger program context, unqualified identifiers need to be interpreted and translated based on the appropriate type. While this is certainly not perfect in this implementation, it is deemed reasonable that some is better than none.

Default Instance of a Form

Additionally, one must consider Forms. Forms automatically have an instance created for them in VB6. While you can create an instance of a form, the most typical use case is to simply reference the object and use the "default instance". Since this doesn't exist in C#, a boilerplate variable of MyForm.instance is automatically pre-pended to each form and included in the converted code. References to forms, then, must have the ...instance... inserted at the appropriate place.

Format

Format is a colon delimited text file. Colons are used instead of commas (,) because function signatures are stored in some cases (which contain commas) and this prevents value escaping.

Speed was not the primary concern when choosing the format. Rather, a light-weight, non-proprietary, easy to use, access, understand, inspect, and debug was the primary consideration.

Layout

For reference, the refscan file is generated to the project folder refs.txt, and is simply a colon-delimited file.

Fields:

  1. Module name
  2. Name
  3. Type (Function, Method, Enum, Control)
  4. Signature (for methods) or Control replacement

Example of refs file

modLinter:LintForms:Function:Function LintForms(Optional ByVal Folder As String, Optional ByVal AutoFix As Boolean = False) As Boolean
modLinter:LintFileList:Function:Function LintFileList(ByVal List As String, ByVal AutoFix As Boolean) As Boolean
modLinter:LintFile:Function:Function LintFile(ByVal FileName As String, Optional ByRef ErrStr As String = "#", Optional ByVal AutoFix As Boolean = False) As Boolean
modLinter:LintFileOptions:Function:Function LintFileOptions(ByVal FileName As String, Optional ByRef ErrStr As String) As Boolean
modLinter:LintFileIndent:Function:Function LintFileIndent(ByVal FileName As String, Optional ByRef ErrStr As String, Optional ByVal AutoFix As Boolean = False) As Boolean
modLinter:LintFileBadCode:Function:Function LintFileBadCode(ByVal FileName As String, Optional ByRef ErrStr As String, Optional ByVal AutoFix As Boolean = False) As Boolean
frm:frm:Form:
frm:frm.fra:Control:VB.Frame
frm:frm.cmdSupport:Control:VB.CommandButton
frm:frm.cmdScan:Control:VB.CommandButton
frm:frm.cmdFile:Control:VB.CommandButton
frm:frm.txtFile:Control:VB.TextBox
frm:frm.cmdLint:Control:VB.CommandButton
frm:frm.cmdConfig:Control:VB.CommandButton
frm:frm.txtStats:Control:VB.TextBox
frm:frm.cmdClasses:Control:VB.CommandButton
frm:frm.cmdModules:Control:VB.CommandButton
frm:frm.cmdAll:Control:VB.CommandButton
frm:frm.cmdForms:Control:VB.CommandButton
frm:frm.cmdExit:Control:VB.CommandButton
frm:frm.txtSrc:Control:VB.TextBox
frm:frm.lblPrg:Control:VB.Label