这是什么 Visual Basic 语法(Begin/End,不是 class)?

What Visual Basic syntax is this (Begin/End, no class)?

最近我的雇主给了我一些旧的源代码,并要求我确定它是否足够可利用以移植到更新的技术,或者我们是否应该从头开始。据我所知,它是用 Visual Studio 编写的 Visual Basic 通用 Windows 项目。我的经验主要是 C#、.Net MVC/Core/Entity Framework,所以我通常可以很好地解读 Visual Basic,但是该项目的大部分内容都包含我似乎无法找到任何信息的语法。

如下图,构成项目大部分的.frm文件包含"Begin VB.Form [FormName]",其中包含一些属性和组件,被End关闭。之后是一些属性和子程序。 class 中似乎没有任何内容(正如我期望来自 C# 的那样)并且 Visual Studio 到处都在抛出错误(主要是 "Statement cannot appear outside of a method body")。

我唯一的猜测是 class 在文件顶部的对象中以某种方式被引用,随后的所有内容都扩展了它,但是许多 .frm 文件根本没有对象并且 Visual Studio 两种方式都抱怨。

那么我在这里错过了什么?我只是项目类型错误,导致 Visual Studio 无法正确解释它吗?这是一些我找不到任何信息的旧 Visual Basic 语法吗?它完全是另一种语言吗?或者它可能是超标准的,我只是不知道我在做什么?

感谢您的帮助!

VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.1#0"; "Mscomctl.ocx"
Begin VB.Form frmEqualizer 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "equalizer settings..."
   ClientHeight    =   4200
   ClientLeft      =   -15
   ClientTop       =   375
   ClientWidth     =   7125
   ControlBox      =   0   'False
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   4200
   ScaleWidth      =   7125
   StartUpPosition =   2  'CenterScreen
   Begin VB.CommandButton CommandCancel 
      Cancel          =   -1  'True
      Caption         =   "Cancel"
      Height          =   315
      Left            =   4080
      TabIndex        =   23
      Top             =   3600
      Width           =   1275
   End
   Begin VB.CommandButton CommandOK 
      Caption         =   "OK"
      Height          =   315
      Left            =   5640
      TabIndex        =   22
      Top             =   3600
      Width           =   1275
   End
   Begin VB.ComboBox ComboPresets 
      Height          =   315
      Left            =   2295
      Style           =   2  'Dropdown List
      TabIndex        =   0
      Top             =   2940
      Width           =   2535
   End
   Begin MSComctlLib.Slider Slider80Hz 
      Height          =   1995
      Left            =   217
      TabIndex        =   1
      TabStop         =   0   'False
      Top             =   420
      Width           =   645
      _ExtentX        =   1138
      _ExtentY        =   3519
      _Version        =   393216
      Orientation     =   1
      Min             =   -1500
      Max             =   1500
      TickStyle       =   2
      TickFrequency   =   150
   End
   Begin MSComctlLib.Slider Slider310Hz 
      Height          =   1995
      Left            =   1552
      TabIndex        =   2
      TabStop         =   0   'False
      Top             =   420
      Width           =   645
      _ExtentX        =   1138
      _ExtentY        =   3519
      _Version        =   393216
      Orientation     =   1
      Min             =   -1500
      Max             =   1500
      TickStyle       =   2
      TickFrequency   =   150
   End
   Begin MSComctlLib.Slider Slider1000Hz 
      Height          =   1995
      Left            =   2902
      TabIndex        =   3
      TabStop         =   0   'False
      Top             =   420
      Width           =   645
      _ExtentX        =   1138
      _ExtentY        =   3519
      _Version        =   393216
      Orientation     =   1
      Min             =   -1500
      Max             =   1500
      TickStyle       =   2
      TickFrequency   =   150
   End
   Begin MSComctlLib.Slider Slider3000Hz 
      Height          =   1995
      Left            =   3562
      TabIndex        =   4
      TabStop         =   0   'False
      Top             =   420
      Width           =   645
      _ExtentX        =   1138
      _ExtentY        =   3519
      _Version        =   393216
      Orientation     =   1
      Min             =   -1500
      Max             =   1500
      TickStyle       =   2
      TickFrequency   =   150
   End
   Begin MSComctlLib.Slider Slider6000Hz 
      Height          =   1995
      Left            =   4237
      TabIndex        =   5
      TabStop         =   0   'False
      Top             =   420
      Width           =   645
      _ExtentX        =   1138
      _ExtentY        =   3519
      _Version        =   393216
      Orientation     =   1
      Min             =   -1500
      Max             =   1500
      TickStyle       =   2
      TickFrequency   =   150
   End
   Begin MSComctlLib.Slider Slider600Hz 
      Height          =   1995
      Left            =   2227
      TabIndex        =   6
      TabStop         =   0   'False
      Top             =   420
      Width           =   645
      _ExtentX        =   1138
      _ExtentY        =   3519
      _Version        =   393216
      Orientation     =   1
      Min             =   -1500
      Max             =   1500
      TickStyle       =   2
      TickFrequency   =   150
   End
   Begin MSComctlLib.Slider Slider170Hz 
      Height          =   1995
      Left            =   892
      TabIndex        =   7
      TabStop         =   0   'False
      Top             =   420
      Width           =   645
      _ExtentX        =   1138
      _ExtentY        =   3519
      _Version        =   393216
      Orientation     =   1
      Min             =   -1500
      Max             =   1500
      TickStyle       =   2
      TickFrequency   =   150
   End
   Begin MSComctlLib.Slider Slider14000Hz 
      Height          =   1995
      Left            =   5602
      TabIndex        =   8
      TabStop         =   0   'False
      Top             =   420
      Width           =   645
      _ExtentX        =   1138
      _ExtentY        =   3519
      _Version        =   393216
      Orientation     =   1
      Min             =   -1500
      Max             =   1500
      TickStyle       =   2
      TickFrequency   =   150
   End
   Begin MSComctlLib.Slider Slider16000Hz 
      Height          =   1995
      Left            =   6262
      TabIndex        =   9
      TabStop         =   0   'False
      Top             =   420
      Width           =   645
      _ExtentX        =   1138
      _ExtentY        =   3519
      _Version        =   393216
      Orientation     =   1
      Min             =   -1500
      Max             =   1500
      TickStyle       =   2
      TickFrequency   =   150
   End
   Begin MSComctlLib.Slider Slider12000Hz 
      Height          =   1995
      Left            =   4927
      TabIndex        =   10
      TabStop         =   0   'False
      Top             =   420
      Width           =   645
      _ExtentX        =   1138
      _ExtentY        =   3519
      _Version        =   393216
      Orientation     =   1
      Min             =   -1500
      Max             =   1500
      TickStyle       =   2
      TickFrequency   =   150
   End
   Begin VB.Label Label2 
      Alignment       =   2  'Center
      Caption         =   "80 Hz"
      Height          =   255
      Left            =   217
      TabIndex        =   21
      Top             =   240
      Width           =   645
   End
   Begin VB.Label Label6 
      Alignment       =   2  'Center
      Caption         =   "310 Hz"
      Height          =   255
      Left            =   1552
      TabIndex        =   20
      Top             =   240
      Width           =   645
   End
   Begin VB.Label Label8 
      Alignment       =   2  'Center
      Caption         =   "1 Khz"
      Height          =   255
      Left            =   2902
      TabIndex        =   19
      Top             =   240
      Width           =   645
   End
   Begin VB.Label Label9 
      Alignment       =   2  'Center
      Caption         =   "3 Khz"
      Height          =   255
      Left            =   3562
      TabIndex        =   18
      Top             =   240
      Width           =   645
   End
   Begin VB.Label Label10 
      Alignment       =   2  'Center
      Caption         =   "6 Khz"
      Height          =   255
      Left            =   4237
      TabIndex        =   17
      Top             =   240
      Width           =   645
   End
   Begin VB.Label Label7 
      Alignment       =   2  'Center
      Caption         =   "600 Hz"
      Height          =   255
      Left            =   2197
      TabIndex        =   16
      Top             =   240
      Width           =   645
   End
   Begin VB.Label Label5 
      Alignment       =   2  'Center
      Caption         =   "170 Hz"
      Height          =   255
      Left            =   877
      TabIndex        =   15
      Top             =   240
      Width           =   645
   End
   Begin VB.Label Label11 
      Alignment       =   2  'Center
      Caption         =   "12 Khz"
      Height          =   255
      Left            =   4897
      TabIndex        =   14
      Top             =   240
      Width           =   645
   End
   Begin VB.Label Label13 
      Alignment       =   2  'Center
      Caption         =   "16 Khz"
      Height          =   255
      Left            =   6262
      TabIndex        =   13
      Top             =   240
      Width           =   645
   End
   Begin VB.Label Label14 
      Alignment       =   2  'Center
      Caption         =   "14 Khz"
      Height          =   255
      Left            =   5602
      TabIndex        =   12
      Top             =   240
      Width           =   645
   End
   Begin VB.Label Label12 
      Caption         =   "Apply WinAmp (TM) presets"
      Height          =   255
      Left            =   2295
      TabIndex        =   11
      Top             =   2640
      Width           =   2415
   End
End
Attribute VB_Name = "frmEqualizer"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Public m_nUserResponse As VbMsgBoxResult

Private Sub ResetEqualizerBands()
    Dim nBands As Integer
    nBands = frmStart.ActiveSoundEditor1.Effects.EqualizerBandGetCount()
    For i = 0 To nBands - 1
        Dim fFrequency As Single
        fFrequency = frmStart.ActiveSoundEditor1.Effects.EqualizerBandGetFrequency(i)
        frmStart.ActiveSoundEditor1.Effects.EqualizerBandSetGain fFrequency, 0
    Next i

    Slider80Hz.Value = 0
    Slider170Hz.Value = 0
    Slider310Hz.Value = 0
    Slider600Hz.Value = 0
    Slider1000Hz.Value = 0
    Slider3000Hz.Value = 0
    Slider6000Hz.Value = 0
    Slider12000Hz.Value = 0
    Slider14000Hz.Value = 0
    Slider16000Hz.Value = 0
End Sub

Private Sub UpdateBandsValues()
    Dim fBandwidth As Single
    Dim fGain As Single

    Dim nBands As Integer
    nBands = frmStart.ActiveSoundEditor1.Effects.EqualizerBandGetCount()
    For i = 0 To nBands - 1
        ' get settings for the specific band, we are interested in knowing the actual "gain"
        Dim fFrequency As Single
        fFrequency = frmStart.ActiveSoundEditor1.Effects.EqualizerBandGetFrequency(i)
        frmStart.ActiveSoundEditor1.Effects.EqualizerBandGetParams fFrequency, fBandwidth, fGain

        Select Case fFrequency
        Case 80
            Slider80Hz.Value = -(fGain * 100)
        Case 170
            Slider170Hz.Value = -(fGain * 100)
        Case 310
            Slider310Hz.Value = -(fGain * 100)
        Case 600
            Slider600Hz.Value = -(fGain * 100)
        Case 1000
            Slider1000Hz.Value = -(fGain * 100)
        Case 3000
            Slider3000Hz.Value = -(fGain * 100)
        Case 6000
            Slider6000Hz.Value = -(fGain * 100)
        Case 12000
            Slider12000Hz.Value = -(fGain * 100)
        Case 14000
            Slider14000Hz.Value = -(fGain * 100)
        Case 16000
            ' this band is available only for sounds with a sample rate equal or higher to 48000 Hz
            Slider16000Hz.Value = -(fGain * 100)
        End Select
    Next i
End Sub

Private Sub ComboPresets_Change()

    If ComboPresets.ListIndex = 0 Then
        ' reset equalizer values and exit
        ResetEqualizerBands
        Exit Sub
    End If

    ' load preset keeping in mind that the first element is 'None' so we have to decrease the value
    frmStart.ActiveSoundEditor1.Effects.EqualizerLoadPresets ComboPresets.ListIndex - 1

    ' update the gain for each band
    UpdateBandsValues
End Sub

Private Sub ComboPresets_Click()
    ComboPresets_Change
End Sub

Private Sub CommandCancel_Click()
    m_nUserResponse = vbCancel

    Me.Hide
End Sub

Private Sub CommandOK_Click()
    m_nUserResponse = vbOK

    Me.Hide
End Sub

Private Sub Form_Load()
    ' fill the combo box with the available presets
    ComboPresets.AddItem "None"
    ComboPresets.AddItem "Classical"
    ComboPresets.AddItem "Club"
    ComboPresets.AddItem "Dance"
    ComboPresets.AddItem "Full Bass"
    ComboPresets.AddItem "Full Bass Treble"
    ComboPresets.AddItem "Full Treble"
    ComboPresets.AddItem "Laptop Speakers"
    ComboPresets.AddItem "Large Hall"
    ComboPresets.AddItem "Live"
    ComboPresets.AddItem "Party"
    ComboPresets.AddItem "Pop"
    ComboPresets.AddItem "Reggae"
    ComboPresets.AddItem "Rock"
    ComboPresets.AddItem "Ska"
    ComboPresets.AddItem "Soft"
    ComboPresets.AddItem "Soft Rock"
    ComboPresets.AddItem "Techno"

    ComboPresets.ListIndex = 0

    Slider6000Hz.Visible = True
    Slider12000Hz.Visible = True
    Slider14000Hz.Visible = True
    Slider16000Hz.Visible = True

    ' hide sliders not useful for certain sample rates
    Dim nSampleRate As Long
    nSampleRate = frmStart.ActiveSoundEditor1.GetFrequency()
    If nSampleRate <= 11025 Then
        Slider6000Hz.Visible = False
        Slider12000Hz.Visible = False
        Slider14000Hz.Visible = False
        Slider16000Hz.Visible = False
    ElseIf nSampleRate <= 22050 Then
        Slider12000Hz.Visible = False
        Slider14000Hz.Visible = False
        Slider16000Hz.Visible = False
    ElseIf nSampleRate <= 44100 Then
        Slider16000Hz.Visible = False
    End If

    ' check if equalizer bands have already been created
    Dim nBands As Integer
    nBands = frmStart.ActiveSoundEditor1.Effects.EqualizerBandGetCount()
    If nBands = 0 Then
        ' create equalizer bands inside the control
        frmStart.ActiveSoundEditor1.Effects.EqualizerBandAdd 80, 12, 0
        frmStart.ActiveSoundEditor1.Effects.EqualizerBandAdd 170, 12, 0
        frmStart.ActiveSoundEditor1.Effects.EqualizerBandAdd 310, 12, 0
        frmStart.ActiveSoundEditor1.Effects.EqualizerBandAdd 600, 12, 0
        frmStart.ActiveSoundEditor1.Effects.EqualizerBandAdd 1000, 12, 0
        frmStart.ActiveSoundEditor1.Effects.EqualizerBandAdd 3000, 12, 0
        frmStart.ActiveSoundEditor1.Effects.EqualizerBandAdd 6000, 12, 0
        ' these band are available only for sounds with a sample rate starting from 44100 Hz
        frmStart.ActiveSoundEditor1.Effects.EqualizerBandAdd 12000, 12, 0
        frmStart.ActiveSoundEditor1.Effects.EqualizerBandAdd 14000, 12, 0
        ' this band is available only for sounds with a sample rate starting from 48000 Hz
        frmStart.ActiveSoundEditor1.Effects.EqualizerBandAdd 16000, 12, 0
    Else
        ' update the gain for each band
        UpdateBandsValues
    End If
End Sub

Private Sub Slider80Hz_Change()
    Dim fGain As Single
    fGain = -(Slider80Hz.Value / 100)
    Slider80Hz.Text = fGain
    frmStart.ActiveSoundEditor1.Effects.EqualizerBandSetGain 80, fGain
End Sub

Private Sub Slider80Hz_Scroll()
    Slider80Hz_Change
End Sub

Private Sub Slider170Hz_Change()
    Dim fGain As Single
    fGain = -(Slider170Hz.Value / 100)
    Slider170Hz.Text = fGain
    frmStart.ActiveSoundEditor1.Effects.EqualizerBandSetGain 170, fGain
End Sub

Private Sub Slider170Hz_Scroll()
    Slider170Hz_Change
End Sub

Private Sub Slider310Hz_Change()
    Dim fGain As Single
    fGain = -(Slider310Hz.Value / 100)
    Slider310Hz.Text = fGain
    frmStart.ActiveSoundEditor1.Effects.EqualizerBandSetGain 310, fGain
End Sub

Private Sub Slider310Hz_Scroll()
    Slider310Hz_Change
End Sub

Private Sub Slider600Hz_Change()
    Dim fGain As Single
    fGain = -(Slider600Hz.Value / 100)
    Slider600Hz.Text = fGain
    frmStart.ActiveSoundEditor1.Effects.EqualizerBandSetGain 600, fGain
End Sub

Private Sub Slider600Hz_Scroll()
    Slider600Hz_Change
End Sub

Private Sub Slider1000Hz_Change()
    Dim fGain As Single
    fGain = -(Slider1000Hz.Value / 100)
    Slider1000Hz.Text = fGain
    frmStart.ActiveSoundEditor1.Effects.EqualizerBandSetGain 1000, fGain
End Sub

Private Sub Slider1000Hz_Scroll()
    Slider1000Hz_Change
End Sub

Private Sub Slider3000Hz_Change()
    Dim fGain As Single
    fGain = -(Slider3000Hz.Value / 100)
    Slider3000Hz.Text = fGain
    frmStart.ActiveSoundEditor1.Effects.EqualizerBandSetGain 3000, fGain
End Sub

Private Sub Slider3000Hz_Scroll()
    Slider3000Hz_Change
End Sub

Private Sub Slider6000Hz_Change()
    Dim fGain As Single
    fGain = -(Slider6000Hz.Value / 100)
    Slider6000Hz.Text = fGain
    frmStart.ActiveSoundEditor1.Effects.EqualizerBandSetGain 6000, fGain
End Sub

Private Sub Slider6000Hz_Scroll()
    Slider6000Hz_Change
End Sub

Private Sub Slider12000Hz_Change()
    Dim fGain As Single
    fGain = -(Slider12000Hz.Value / 100)
    Slider12000Hz.Text = fGain
    frmStart.ActiveSoundEditor1.Effects.EqualizerBandSetGain 12000, fGain
End Sub

Private Sub Slider12000Hz_Scroll()
    Slider12000Hz_Change
End Sub

Private Sub Slider14000Hz_Change()
    Dim fGain As Single
    fGain = -(Slider14000Hz.Value / 100)
    Slider14000Hz.Text = fGain
    frmStart.ActiveSoundEditor1.Effects.EqualizerBandSetGain 14000, fGain
End Sub

Private Sub Slider14000Hz_Scroll()
    Slider14000Hz_Change
End Sub

Private Sub Slider16000Hz_Change()
    Dim fGain As Single
    fGain = -(Slider16000Hz.Value / 100)
    Slider16000Hz.Text = fGain
    frmStart.ActiveSoundEditor1.Effects.EqualizerBandSetGain 16000, fGain
End Sub

Private Sub Slider16000Hz_Scroll()
    Slider16000Hz_Change
End Sub

VB6(和 VBA)源代码文件包含的数据比 VBIDE 显示的要多。一方面,属性在 VBE 的代码窗格中是非法的。

如果将该文件导入 VBE,您会看到编辑器模块内容从这里开始(该行可能是 Option Explicit 顺便说一句):

Public m_nUserResponse As VbMsgBoxResult

上面的所有内容都是设计器元数据。来自 C#,您应该熟悉 WinForms 最初是如何类似的混乱(#region 尽管如此),直到 partial classes 得到支持。

Begin VB.Form块可以被认为是某种frmEqualizer.designer.vb部分class;代码文件 本身 一个 class 定义,如以下属性所示:

Attribute VB_Name = "frmEqualizer"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

如果您正在翻译此代码或将其迁移到 .NET/WinForms,那么 Begin VB.Form 块就是您的布局元数据,它告诉 VB 在表单的哪个位置加载哪些控件,以及它们的设计器属性是什么:

   Begin MSComctlLib.Slider Slider14000Hz 
      Height          =   1995
      Left            =   5602
      TabIndex        =   8
      TabStop         =   0   'False
      Top             =   420
      Width           =   645
      _ExtentX        =   1138
      _ExtentY        =   3519
      _Version        =   393216
      Orientation     =   1
      Min             =   -1500
      Max             =   1500
      TickStyle       =   2
      TickFrequency   =   150
   End

例如,此块定义了一个名为 Slider14000HzMSComctlLib.Slider 设计时实例,它从 -1500 滑动到 1500,宽 645 缇,高 1995 缇,位于(顶部:420,left:5602) 在表单坐标中(从左上角算起 twips)。

这一行:

Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.1#0"; "Mscomctl.ocx"

正在加载使用 CLSID {831FDD16-0C5C-11D2-A9FC-0000F8754DA1} 注册的 COM 对象,版本 2.1,库 "Mscomctl.ocx" - 又名 Microsoft Common Controls,32 位库定义这里使用的Slider控件(如果是VB代码,只能在32位Office主机上运行)

如果表单有二进制元数据(例如嵌入的图标或图像),在与 .frm 相同的文件夹中应该有一个同名的 .frx 文件。