Hey guys. I've been programming for a long time, but there's something I've never figured out how to do in all this time. Surely there is a way to turn the following code into a sub so I don't have the same boilerplate show form code in use a thousand times in a program:
Example:
Basically, I need a way to do this provided the input of the form's instance variable. Ideally something like:Code:Public InstanceOfFrmGeneric As frmGeneric If InstanceOfFrmGeneric Is Nothing Then InstanceOfFrmGeneric = New frmGeneric() InstanceOfFrmGeneric.Show() Else If InstanceOfFrmGeneric.IsDisposed Then InstanceOfFrmGeneric = New frmGeneric() InstanceOfFrmGeneric.Show() Else InstanceOfFrmGeneric.Focus() End If End If
Anyone know how to do this? It's probably a simple Typing thing or something, but that's not an area I'm good at since it doesn't seem to flow with the normal language.Code:Private Sub showForm(ByRef InstanceOfForm As Form) 'Pseudo-code If InstanceOfForm Is Nothing Then InstanceOfForm = New Magic Thing Letting Me Make New Instance Of InstanceOfForm Based on Its Type Or Whatever InstanceOfForm.Show() Else If InstanceOfForm.IsDisposed Then InstanceOfForm = New New Magic Thing Letting Me Make New Instance Of InstanceOfForm Based on Its Type Or Whatever InstanceOfForm.Show() Else InstanceOfForm.Focus() End If End If End Sub


Reply With Quote



