title: Why is my VBA function returning 0?
body: <p>Consider the following function in VBA (note that it's been edited based on the answers given so now it's working - see the edit history for the original version):</p>
  
  <pre><code>Function DisplayNode(ByRef Nodes)
  
      Dim xNode As Object
      For Each xNode In Nodes
  
          If xNode.nodeName = "LastTradePriceOnly" Then
              DisplayNode = xNode.Text
              Exit Function
          End If
          If xNode.HasChildNodes Then
              DisplayNode = DisplayNode (xNode.ChildNodes)
          End If
  
     Next xNode
  
  End Function
  </code></pre>
  
  <p>This function parses an XML response and returns the value of one of the nodes, <code>LastTradePriceOnly</code>.</p>
  
  <p>The Nodes argument is a <code>MSXML.DOMDocument</code> object. When I use <code>msgBox</code> to print the value of <code>xNode.text</code> the value I am expecting is output. However, when I call this function from another function, 0 is returned.</p>
  
  <p>Any thoughts on why I might be returning 0?</p>