Results 1 to 4 of 4

Thread: [RESOLVED] Code Optimsation

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    808

    Resolved [RESOLVED] Code Optimsation

    Can someone suggest a way of optimising this code?
    I have multiple cases of this and it's annoying to add or update.
    I don't care what the sender is. I just want to delete "Varies" from the combobox.
    HTML Code:
        Private Sub ComboBox_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cboShape.Click, cboGrade.Click, cboDiameter.Click, cboStyle.Click, cboView.Click
            If sender Is cboShape Then : If cboShape.Items.Contains("Varies") Then : cboShape.Items.Remove("Varies") : End If
            ElseIf sender Is cboDiameter Then : If cboDiameter.Items.Contains("Varies") Then : cboDiameter.Items.Remove("Varies") : End If
            ElseIf sender Is cboGrade Then : If cboGrade.Items.Contains("Varies") Then : cboGrade.Items.Remove("Varies") : End If
            ElseIf sender Is cboStyle Then : If cboStyle.Items.Contains("Varies") Then : cboStyle.Items.Remove("Varies") : End If
            ElseIf sender Is cboView Then : If cboView.Items.Contains("Varies") Then : cboView.Items.Remove("Varies") : End If
            ElseIf sender Is cboScale Then : If cboScale.Items.Contains("Varies") Then : cboScale.Items.Remove("Varies") : End If
            ElseIf sender Is cboMeshSize Then : If cboMeshSize.Items.Contains("Varies") Then : cboMeshSize.Items.Remove("Varies") : End If
            ElseIf sender Is cboMeshType Then : If cboMeshType.Items.Contains("Varies") Then : cboMeshType.Items.Remove("Varies") : End If
            ElseIf sender Is cboCouplerBrand Then : If cboCouplerBrand.Items.Contains("Varies") Then : cboCouplerBrand.Items.Remove("Varies") : End If
            ElseIf sender Is cboCouplerType Then : If cboCouplerType.Items.Contains("Varies") Then : cboCouplerType.Items.Remove("Varies") : End If
            ElseIf sender Is cboEndACouplerThread Then : If cboEndACouplerThread.Items.Contains("Varies") Then : cboEndACouplerThread.Items.Remove("Varies") : End If
            ElseIf sender Is cboEnd2CouplerThread Then : If cboEnd2CouplerThread.Items.Contains("Varies") Then : cboEnd2CouplerThread.Items.Remove("Varies") : End If
            ElseIf sender Is cboMembers Then : If cboMembers.Items.Contains("Varies") Then : cboMembers.Items.Remove("Varies") : End If
            ElseIf sender Is cboDrawingTitle Then : If cboDrawingTitle.Items.Contains("Varies") Then : cboDrawingTitle.Items.Remove("Varies") : End If
            End If
        End Sub

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    808

    Re: Code Optimsation

    Ah crap.
    A simple google search. Can I delete this post?

    Dim myComboBox = CType(sender, ComboBox)
    If myComboBox.Items.Contains("Varies") Then
    myComboBox.Items.Remove("Varies")
    End If

  3. #3
    Fanatic Member Delaney's Avatar
    Join Date
    Nov 2019
    Location
    Paris, France
    Posts
    731

    Re: [RESOLVED] Code Optimsation

    No, keep your post, it could always be useful to someone else
    The best friend of any programmer is a search engine
    "Don't wish it was easier, wish you were better. Don't wish for less problems, wish for more skills. Don't wish for less challenges, wish for more wisdom" (J. Rohn)
    “They did not know it was impossible so they did it” (Mark Twain)

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    107,760

    Re: [RESOLVED] Code Optimsation

    Just one thing to note: use DirectCast rather than CType. It's not a big deal but it is the more correct option.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width