Efficiency Help.

cugone

Newcomer
Joined
Apr 30, 2008
Messages
19
I have the following code:

Code:
        Select Case localType
            Case "Relations"
                i = 0
                For j = 0 To Me.listRelations.Count - 1
                    li.SubItems.Add(New ListViewItem.ListViewSubItem())
                    li.Text = Me.listRelations.Item(j).Name
                    i += 1
                    li.SubItems(i).Text = Me.listRelations.Item(j).Relation

                    'Copy listview item, attempt to store into array.
                    li_copy = TryCast(li.Clone(), ListViewItem)
                    If li_copy Is Nothing Then
                        MessageBox.Show("There was an error inserting record " & _
                        (ItemCount + 1).ToString & _
                        " into the list. It contains invalid data or is empty.", _
                        My.Application.Info.Title, _
                        MessageBoxButtons.OK, _
                        MessageBoxIcon.Error)
                        Continue For
                    Else
                        ReDim Preserve aryItems(ItemCount)
                        aryItems(ItemCount) = li_copy
                    End If

                    ItemCount += 1

                    'Reset values for populating with next record.
                    li.SubItems.Clear()
                    li.Text = ""
                    li_copy = Nothing
                    i = 0
                Next j
...

It repeats exactly as is multiple times with the exception of "listRelations" changes to one of many other different object names based on the select case at the time.

I was wondering, is there a way to put this all in one subroutine and have the object acted on changed based on string parameters passed in?
 
You may want to look into this method:
Code:
this.Controls.Find(string,true);
you will then need to pass in the exact name, not just part of it.
 
I was thinking about that, but the "list..." prefixed objects are not controls, they are List (Of T) objects.
 
Something like this should work, no?
C#:
public void doWork<T>(IList<T> theList)
{

}

Visual Basic:
Public Sub doWork(Of T)(theList As IList(Of T))
    
End Sub
 
Back
Top