When converting VB6 code to VB.NET, I have several problems. I will consider here, in particular, here.
Original code VB6:
Public Sub dynForm(sFormName As String, loadingForm As Form, Optional resizeMe As Boolean = True)
On Error GoTo ErrHandler
'Used to dynamically open a form based on its name.
Dim oForm As Form
'Add a Form to the collection
Set oForm = Forms.Add(sFormName)
'Load the Form
Load oForm
If resizeMe Then
setFrmSize oForm
End If
centerForm oForm
'Show The Form
oForm.Show 1, loadingForm
If oForm Is Nothing Then Exit Sub
Set oForm = Nothing
Exit Sub
ErrHandler:
logError Err.Description & vbCrLf & "sFrm:" & sFormName & " not found!", Err.Number, "common.dynForm", ErrorMsg
End Sub
The conversion process gives the following (I shortened conversion comments that link to links that are no longer valid):
Public Sub dynForm(ByRef sFormName As String, ByRef loadingForm As System.Windows.Forms.Form, Optional ByRef resizeMe As Boolean = True)
On Error GoTo ErrHandler
'Used to dynamically open a form based on its name.
Dim oForm As System.Windows.Forms.Form
'Add a Form to the collection
'UPGRADE_ISSUE: Forms method Forms.Add was not upgraded.
oForm = Forms.Add(sFormName)
'Load the Form
'UPGRADE_ISSUE: Load statement is not supported.
Load(oForm)
If resizeMe Then
setFrmSize(oForm)
End If
centerForm(oForm)
'Show The Form
VB6.ShowForm(oForm, 1, loadingForm)
If oForm Is Nothing Then Exit Sub
'UPGRADE_NOTE: Object oForm may not be destroyed until it is garbage collected.
oForm = Nothing
Exit Sub
ErrHandler:
logError(Err.Description & vbCrLf & "sFrm:" & sFormName & " not found!", Err.Number, "common.dynForm", ErrorType.ErrorMsg)
End Sub
The following errors were returned:
The name "Forms" was not declared. The name "Download" has not been announced.
I just commented on the Load statement. But adding forms to the collection turned out to be a tougher nut to crack.
I tried several options:
oForm = System.Windows.Forms.Form.Add(sFormName)
returns an error: "Add" is not a member of "System.Windows.Forms.Form"
oForm = System.Windows.Forms.Form.AddOwnedForm(sFormName)
returns an error: a link to a non-general user requires a link to an object.
oForm = My.Forms.Add(sFormName)
: "" "RSC_Reports.My.MyProject.MyForms".
, , ?