title: VB Script - Undefined variable
body: <p>I'm getting 'variable is undefined', I'm guessing this has something to do with the scope of variables in vbscript, but my knowledge is limited with this.</p>
  
  <p>I know the loading of the email addresses works and the actual emailing because I have checked these separately.  I'm trying to loop through a list of email addresses and send the log file to each..</p>
  
  <p>Any additional information would be great!</p>
  
  <p>First, there is a var array at the top of the file:</p>
  
  <pre><code>dim emails()
  
  function getEmailAddresses()
  
      dim objFSO
      dim objConfigFile
      dim strLine
      dim iCounter
  
      const ForReading = 1, ForWriting = 2, ForAppending = 8  
  
      set objFSO = createobject("Scripting.FileSystemObject")
      set objConfigFile = objFSO.OpenTextFile("emailAddresses.config", ForReading)
  
      iCounter = 0
  
      do while not objConfigFile.AtEndOfStream
          redim preserve emails(iCounter)
          strLine = trim(objConfigFile.ReadLine)
          emails(iCounter) = strLine
          iCounter = iCounter + 1
      loop
  
      objConfigFile.Close
  
  end function
  
  function writetolog(strLogtext) 
      dim objFSO
      dim objLogfile
  
      const ForReading = 1, ForWriting = 2, ForAppending = 8
  
      set objFSO = createobject("Scripting.FileSystemObject")
      set objLogfile = objFSO.OpenTextFile("xxx.log", ForAppending, true) 
      objLogfile.Writeline now() &amp; "  -  " &amp; strLogText   
      objLogfile.Close 
  
      call EmailLogFile(strLogText)
  
  end function
  
  
  function EmailLogFile(bodyText)
  
      for each emailAddress in emails
  
          set objEmail = CreateObject("CDO.Message")
          objEmail.From = "File.Mover@xxxxxxx.xxx"
  
          objEmail.To = emailAddress
          objEmail.Subject = "File Move Log" 
          objEmail.Textbody = bodyText
          objEmail.Configuration.Fields.Item _
              ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
          objEmail.Configuration.Fields.Item _
              ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = _
          "xxxxxx" 
          objEmail.Configuration.Fields.Item _
              ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
          objEmail.Configuration.Fields.Update
          objEmail.Send
  
     next
  end function
  </code></pre>