I was recently given some old source code from my employer and asked to determine if it was salvageable enough to port to newer technology or if we should just start from scratch. From what I can tell it is a Visual Basic, Universal Windows project written in Visual Studio. My experience is primarily in C#, .Net MVC/Core/Entity Framework, so I can usually decipher Visual Basic pretty well, but much of the project consists of syntax that I cannot seem to find any information on.
As shown below, the .frm files that make up most of the project contain "Begin VB.Form [FormName]", which contains some attributes and components and is closed by End. After that there are some attributes and subroutines. Nothing appears to be wrapped in a class (as I would expect coming from C#) and Visual Studio is throwing errors everywhere (mostly "Statement cannot appear outside of a method body").
My only guess is that the class is somehow referenced in the Object at the top of the file and everything following extends that, but many of the .frm files do not have an Object at all and Visual Studio complains either way.
So what am I missing here? Do I just have the project type wrong, preventing Visual Studio from properly interpreting it? Is this some old Visual Basic syntax that I cannot find any info on? Is it another language entirely? Or perhaps it is super standard and I just have no idea what I'm doing? 😄
Thanks for the help!
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 (and VBA) source code files contain more data than what the VBIDE visibly shows. Attributes, for one, are illegal in the VBE's code panes.
If you imported that file into the VBE, you would see that the in-editor module content begins here (that line should probably be saying Option Explicit
BTW):
Public m_nUserResponse As VbMsgBoxResult
Everything above that is designer metadata. Coming from C#, you should be familiar with how WinForms was originally a similar mess (#region
notwithstanding), until partial
classes became supported.
The Begin VB.Form
block can be thought of as some kind of frmEqualizer.designer.vb
partial class; the code file itself is a class definition, as indicated by these attributes:
Attribute VB_Name = "frmEqualizer"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
If you're translating this code or migrating it to .NET/WinForms, then the Begin VB.Form
block is your layout metadata, telling VB what controls to load where on the form, and what their designer properties are:
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
For example this block defines a MSComctlLib.Slider
design-time instance named Slider14000Hz
that slides from -1500 to 1500, 645 twips wide and 1995 twips tall, located at (top:420, left:5602) in form coordinates (twips from upper-left corner).
This line:
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.1#0"; "Mscomctl.ocx"
Is loading a COM object registered with CLSID {831FDD16-0C5C-11D2-A9FC-0000F8754DA1}
, version 2.1, library "Mscomctl.ocx" - aka Microsoft Common Controls, the 32-bit library that defines the Slider
control in use here (if it's VBA code, it only runs in a 32-bit Office host).
If the form had binary metadata (e.g. embedded icons or images), there should be a .frx
file in the same folder as the .frm
, with the same name.