How do I simplify this code

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
 
T

Tim Wilson

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top