G
Gary Shell
I have two forms both derived by inheriting the same base form. I have a
third form that needs to instantiate one of those two forms, set some
Protected properties on the two forms, display the form, test a property of
the from when it is closed and then dispose of the instantiated form.
The third form has two radio buttons used to determine wich form to
instantiate. The folllowing code fails to compile due to the scope of the
DIM statement.
Private Sub btnEditTheClass_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnEditTheClass.Click
If RadioButton_BP.Checked Then
Dim frm As New frmBP_Class
ElseIf RadioButton_IO.Checked Then
Dim frm As New frmIO_Class
End If
'pass a connection to SQL
frm.sqlConnection = SqlConnection1
'pass the TheClass to be edited
frm.TheClass = txtTheClass.Text
'set EDIT mode
frm.Mode = frm.Modes.EditMode
'show as a MODAL form
frm.ShowDialog()
'if the data was updated
If frm.DataUpdated = True Then
'display the updated data
txtTheClass.Text = frm.TheClass
End If
'dispose of the form
frm.Dispose()
End Sub
Because of this I have to resort to the following:
Private Sub btnEditTheClass_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnEditTheClass.Click
If RadioButton_BP.Checked Then
Dim frm As New frmBP_Class
'pass a connection to SQL
frm.sqlConnection = SqlConnection1
'pass the TheClass to be edited
frm.TheClass = txtTheClass.Text
'set EDIT mode
frm.Mode = frm.Modes.EditMode
'show as a MODAL form
frm.ShowDialog()
'if the data was updated
If frm.DataUpdated = True Then
'display the updated data
txtTheClass.Text = frm.TheClass
End If
'dispose of the form
frm.Dispose()
ElseIf RadioButton_IO.Checked Then
Dim frm As New frmIO_Class
'pass a connection to SQL
frm.sqlConnection = SqlConnection1
'pass the TheClass to be edited
frm.TheClass = txtTheClass.Text
'set EDIT mode
frm.Mode = frm.Modes.EditMode
'show as a MODAL form
frm.ShowDialog()
'if the data was updated
If frm.DataUpdated = True Then
'display the updated data
txtTheClass.Text = frm.TheClass
End If
'dispose of the form
frm.Dispose()
End If
End Sub
YUCH!!!!! That is truly UGLY. But I, for the life of me, can't find any
other way to do this. Suggestions? Clue by fours?
Thanks,
Gary
third form that needs to instantiate one of those two forms, set some
Protected properties on the two forms, display the form, test a property of
the from when it is closed and then dispose of the instantiated form.
The third form has two radio buttons used to determine wich form to
instantiate. The folllowing code fails to compile due to the scope of the
DIM statement.
Private Sub btnEditTheClass_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnEditTheClass.Click
If RadioButton_BP.Checked Then
Dim frm As New frmBP_Class
ElseIf RadioButton_IO.Checked Then
Dim frm As New frmIO_Class
End If
'pass a connection to SQL
frm.sqlConnection = SqlConnection1
'pass the TheClass to be edited
frm.TheClass = txtTheClass.Text
'set EDIT mode
frm.Mode = frm.Modes.EditMode
'show as a MODAL form
frm.ShowDialog()
'if the data was updated
If frm.DataUpdated = True Then
'display the updated data
txtTheClass.Text = frm.TheClass
End If
'dispose of the form
frm.Dispose()
End Sub
Because of this I have to resort to the following:
Private Sub btnEditTheClass_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnEditTheClass.Click
If RadioButton_BP.Checked Then
Dim frm As New frmBP_Class
'pass a connection to SQL
frm.sqlConnection = SqlConnection1
'pass the TheClass to be edited
frm.TheClass = txtTheClass.Text
'set EDIT mode
frm.Mode = frm.Modes.EditMode
'show as a MODAL form
frm.ShowDialog()
'if the data was updated
If frm.DataUpdated = True Then
'display the updated data
txtTheClass.Text = frm.TheClass
End If
'dispose of the form
frm.Dispose()
ElseIf RadioButton_IO.Checked Then
Dim frm As New frmIO_Class
'pass a connection to SQL
frm.sqlConnection = SqlConnection1
'pass the TheClass to be edited
frm.TheClass = txtTheClass.Text
'set EDIT mode
frm.Mode = frm.Modes.EditMode
'show as a MODAL form
frm.ShowDialog()
'if the data was updated
If frm.DataUpdated = True Then
'display the updated data
txtTheClass.Text = frm.TheClass
End If
'dispose of the form
frm.Dispose()
End If
End Sub
YUCH!!!!! That is truly UGLY. But I, for the life of me, can't find any
other way to do this. Suggestions? Clue by fours?
Thanks,
Gary