if ctl.Name.Substring(0, 2).ToUpper.Equals("UP") then
MoveUp = True
else
MoveUp = False
end if
To shorten the 'thisLV', you could take off the last number and use a select case with that.
Main Topics
Browse All TopicsI have the following script which is using 'Select Case':
Dim ctl As ToolStripButton = CType(sender, ToolStripButton)
Dim MoveUp As Boolean = False
Dim thisLV As ListView = AccountsLV
Select Case ctl.Name
Case "UpBtn1"
MoveUp = True
thisLV = ListView1
Case "DownBtn1"
MoveUp = False
thisLV = ListView1
Case "UpBtn2"
MoveUp = True
thisLV = ListView2
Case "DownBtn2"
MoveUp = False
thisLV = ListView2
Case "UpBtn3"
MoveUp = True
thisLV = ListView3
Case "DownBtn3"
MoveUp = False
thisLV = ListView3
End Select
As you can see, if the Name of the ToolStripButton begins with "Up", then I want 'MoveUp = True'. If not, then I want 'MoveUp = False'. Then, I want the number at the end of the toolstripbutton name to correspond with the ListView (i.e. DownBtn1 => 'thisLV = ListView1' or UpBtn3 => 'thisLV = ListView3')
Is there anyway to condense this? I am planning on having over 20 cases like this and don't want the code to get to lengthy.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Working from the inner to the outer we start with:
"ListView" & ctl.Name.Substring(ctl.Nam
This extracts just the number portion of the Control name by grabbing everything past the "Btn" in the controls name. We then append this number to "ListView" giving us:
"UpBtn1" --> "ListView1"
"DownBtn1" --> "ListView1"
"UpBtn2" --> "ListView2"
"DownBtn2" --> "ListView2"
etc...
The Me.Controls.Find() method searches a container for a control that has a matching name. The second parameter of True/False tells Find() whether to seach child containers. This is necessary if the ListViews are actually NOT contained directly by the form (such as in a Panel for instance). The Controls.Find() method returns an ARRAY of Controls that match so the "(0)" part on the end is so that we only use the first match found.
A more verbose version might be:
Dim ctl As ToolStripButton = CType(sender, ToolStripButton)
Dim MoveUp As Boolean = ctl.Name.StartsWith("Up")
Dim thisLV As ListView = AccountsLV
Dim btnPos As Integer = ctl.Name.IndexOf("Btn")
If btnPos > -1 Then
Dim ListViewName As String = "ListView" & ctl.Name.Substring(btnPos + 3)
Dim matches() As Control = Me.Controls.Find(ListViewN
If matches.Length > 0 Then
thislv = matches(0)
Else
MessageBox.Show(ListViewNa
End If
Else
MessageBox.Show(ctl.Name, "Unexpected Control Name")
End If
Business Accounts
Answer for Membership
by: Idle_MindPosted on 2007-10-03 at 13:29:24ID: 20009788
Sure...try something like:
" & ctl.Name.Substring(ctl.Nam e.IndexOf( "Btn") + 3), True)(0)
Dim ctl As ToolStripButton = CType(sender, ToolStripButton)
Dim MoveUp As Boolean = ctl.Name.StartsWith("Up")
Dim thisLV As ListView = Me.Controls.Find("ListView