Hi
I want to make a generic function to replace these 2 functions in a
web site,
As you can see both functions do exactly the same thing, except one
works on a MenuItemCollection and teh other takes TreeNodeCollection
as parameters.
I can write one function
function getitem(byval oCol as ICollection, byval skey as string) as
###
But I'm stuck as to know what to return and how to define oItem and
o.
Also how do I call oItem.ChildItems or oItem.ChildNodes inside funcs.
Not a big prob having 2 versions but would liek to learn if possible..
Thanks Bob
Private Shared Function getMenuitem(ByVal oCol As
MenuItemCollection, ByVal sKey As String) As MenuItem
' return menu item with sKey in the collection
Dim oItem As MenuItem
Dim o As MenuItem
For Each oItem In oCol
If oItem.Value = sKey Then
Return oItem
ElseIf oItem.ChildItems.Count > 0 Then
o = getMenuitem(oItem.ChildItems, sKey)
If o IsNot Nothing Then
Return o
End If
End If
Next
Return Nothing
End Function
Private Shared Function getTreeNode(ByVal oCol As
TreeNodeCollection, ByVal sKey As String) As TreeNode
' return menu item with sKey in the collection
Dim oItem As TreeNode
Dim o As TreeNode
For Each oItem In oCol
If oItem.Value = sKey Then
Return oItem
ElseIf oItem.ChildNodes.Count > 0 Then
o = getTreeNode(oItem.ChildNodes, sKey)
If o IsNot Nothing Then
Return o
End If
End If
Next
Return Nothing
End Function