Item Property Example

The following example demonstrates returning a value by indexing an item in the collection. This example returns the label for the first navigation node in the navigation structure of the active web.

Note   You access the NavigationNodes collection through the Children property of the RootNavigationNode property of the active web.

Private Sub GetNavigationNode()
Dim myWeb As Web
Dim myNavNodes As NavigationNodes
Dim myNavNodeLabel As String

Set myWeb = ActiveWeb

myNavNodeLabel _
    = myWeb.RootNavigationNode.Children.Item(0).Label
End Sub

Note   You can also omit the Item property and access the specified item using the following coding method. The following statement returns the same value as the previous statement. For more information and another example of omitting the Item property, see the last paragraph in this section.

myNavNodeLabel _
    = myWeb.RootNavigationNode.Children(0).Label

The following statement returns the contents of a META tag that exists on a web page in the active web, and demonstrates the PropertyKey As String argument.

myMetaTagContents _
    = ActiveWeb.RootFolder.Files.Item(0).MetaTags.Item("generator")

Note   On the HTML tab in Page view, FrontPage displays this meta tag as initially capped (Generator). However, the value of the meta tag item is all lowercase letters (generator). If you capitalize the first letter of a META tag name and use it as search criteria in a Visual Basic program, your search will fail.

It isn't always necessary to specify the index or property name of the Item property when returning values from a collection. The following example returns a list of file names of each web page that contains a META tag name equivalent to "generator" in the active web, without specifying the Item property. FindGeneratorTags retrieves a list of the files that contain the "generator" META tag and adds value of the Item property to the variable myMetaTag, because in this case the value of the Item property is the same as the file name. This is different from the previous example, which returned the contents of the "generator" META tag.

Private Function FindGeneratorTags() As String
Dim myWeb As Web
Dim myMetaTags As MetaTags
Dim myMetaTag As Variant
Dim myFiles As WebFiles
Dim myFile As WebFile
Dim myMetaTagName As String
Dim myReturnFileName As String

Set myWeb = ActiveWeb
Set myFiles = myWeb.RootFolder.Files

With myWeb
    For Each myFile In myFiles
        Set myMetaTags = myFile.MetaTags
        For Each myMetaTag In myMetaTags
            myMetaTagName = myMetaTag
            If myMetaTagName = "generator" Then
                myReturnFileName = myReturnFileName & myFile.Name
            End If
        Next
    Next
End With
FindGeneratorTags = myReturnFileName
End Function