|
-
Oct 15th, 2021, 01:57 PM
#1
Thread Starter
Fanatic Member
[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
-
Oct 15th, 2021, 02:07 PM
#2
Thread Starter
Fanatic Member
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
-
Oct 15th, 2021, 02:37 PM
#3
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)
-
Oct 15th, 2021, 07:46 PM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|