title: How to create a dynamic array and sum its values
body: <p>The vbs code below writes a word count (as integer) for each line of string in a document. How do I create a dynamic array (of each line's word count) and sum up the values?</p>
  
  <pre><code>Function AddLineNum()
  Dim nLine, sLine, nCount, nLen
  
  nCount = 0
  Do Until oInStream.AtEndOfStream
  nLine = oInStream.Line
  sLine = oInStream.ReadLine
  
  'working word count for each line
  nLen  = len(sLine) - len(Replace (sLine, " ", "")) +1
  
  oOutStream.WriteLine nLen
  
  nCount = nCount + 1
  Loop
  AddLineNum = nCount
  
  End Function
  </code></pre>