How do I simplify this code

  • Thread starter Thread starter dbuchanan
  • Start date Start date
D

dbuchanan

I have a select case which opens various forms as ShowDialog. Notice
the repetition;

\\
Case "btnManageJobs"
Dim f As New f010Jobs
Me.Visible = False
f.ShowDialog()
Me.Visible = True

Case "btnSeqOfOper"
Dim f As New f050SqOO
Me.Visible = False
f.ShowDialog()
Me.Visible = True

Case "btnViewer"
Dim f As New f060View
Me.Visible = False
f.ShowDialog()
Me.Visible = True
//

How can I take the code...

\\
Me.Visible = False
f.ShowDialog()
Me.Visible = True
//

.... and put it after the select case block?

IOW is there any way to declaire "f" before the select case block and
give it the form name within the select case and then run the
"f.ShowDialog" after the block.

Orrrrr is there a simpler way to do this?

thank you,
dbuchanan
 
You could do that in the following way...

Private Sub Button_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)

Dim f As Form = Nothing

Select Case True
Case sender Is Button1
f = New Form2
Case sender Is Button2
f = New Form3
End Select

If (Not f Is Nothing) Then
Me.Visible = False
f.ShowDialog()
Me.Visible = True
End If

End Sub
 
Back
Top