Christopher Hunt Christopher Hunt - 2 months ago 8
Vb.net Question

How do I simplify this code?

I'm really new to vb.net and am looking to make this code less redundant, but I'm not sure how

ONE.DisplayLayout.Override.FilterOperandStyle = FilterOperandStyle.FilterUIProvider
ONE.DisplayLayout.Override.FilterUIType = FilterUIType.FilterRow
ONE.DisplayLayout.Override.FilterUIProvider = New SupportDialogs.FilterUIProvider.UltraGridFilterUIProvider()

TWO.DisplayLayout.Override.FilterOperandStyle = FilterOperandStyle.FilterUIProvider
TWO.DisplayLayout.Override.FilterUIType = FilterUIType.FilterRow
TWO.DisplayLayout.Override.FilterUIProvider = New SupportDialogs.FilterUIProvider.UltraGridFilterUIProvider()

THREE.DisplayLayout.Override.FilterOperandStyle = FilterOperandStyle.FilterUIProvider
THREE.DisplayLayout.Override.FilterUIType = FilterUIType.FilterRow
THREE.DisplayLayout.Override.FilterUIProvider = New SupportDialogs.FilterUIProvider.UltraGridFilterUIProvider()


As you can see, the only difference is ONE, TWO and THREE. How do I simplify this without repeating?

Thanks!

Answer

I don't know what is the Type of ONE, TWO and THREE, but you can make a sub :

Public Sub DoStuff(Data As YourType)
    Data.DisplayLayout.Override.FilterOperandStyle = FilterOperandStyle.FilterUIProvider
    Data.DisplayLayout.Override.FilterUIType = FilterUIType.FilterRow
    Data.DisplayLayout.Override.FilterUIProvider = New SupportDialogs.FilterUIProvider.UltraGridFilterUIProvider()
End Sub

And you call it by doing

DoStuff(ONE)
DoStuff(TWO)
DoStuff(THREE)