UtterAccess HomeUtterAccess Wiki

Welcome Guest ( Log In | Register )

Custom Search
Edit Discussion
> CountNodes    



Private Sub Command10_Click()
   Dim strPath     As String
   Dim strFile     As String
   Dim strNode     As String
   Dim lngNodes    As Long
   strPath = "C:\MyPath"
   strFile = "MyFile"
   strNode = "MyNode"
   lngNodes = CountNodes(strPath, strFile, strNode)
   Debug.Print "There are " & lngNodes & " " & strNode & " Nodes"
End Sub



' CountNodes
' http://www.utteraccess.com/wiki/CountNodes
' Code courtesy of UtterAccess Wiki
' Original submission by Diego F.Pereira-Perdomo
' Licensed under Creative Commons License
' http://creativecommons.org/licenses/by-sa/3.0/
' You are free to use this code in any application,
' provided this notice is left unchanged.
' rev  date                          brief descripton
' 1.0  2013-10-27                    Counts the number of times a specific node appears in a xml document.
'                                       strPath: A string that contains the Path where the File is located.
'                                       strFile: A string that contains the Name of the File.
'                                       strNode: The Name of the Node.



Option Compare Database
Option Explicit

Dim lngC As Long



Public Function CountNodes(strPath As String, _
                           strFile As String, _
                           strNode As String) As Long
   Dim oFSO    As Scripting.FileSystemObject
   Dim oTSt    As Scripting.TextStream
   Dim strPF   As String
   Dim strRL   As String

   strPF = strPath & "\" & strFile
   Set oFSO = New Scripting.FileSystemObject
   Set oTSt = oFSO.OpenTextFile(strPF, ForReading)
   With oTSt
       Do While Not .AtEndOfStream
           Counting Trim$(.ReadLine), strNode
   End With
   Set oFSO = Nothing
   CountNodes = lngC
   lngC = 0
End Function



Sub Counting(strRL As String, strNode As String)
   If strRL Like "*<" & strNode & "[> ]*" Then
           lngC = lngC + 1
   End If
End Sub
Edit Discussion
Custom Search

Thank you for your support!
This page has been accessed 2,854 times.  This page was last modified 02:34, 28 October 2013 by genoma111.   Disclaimers