VB脚本 - 未定义的变量

时间:2011-02-23 13:55:41

标签: vbscript

我得到'变量未定义',我猜这与vbscript中的变量范围有关,但我的知识受此限制。

我知道电子邮件地址的加载工作和实际的电子邮件,因为我已经单独检查了这些。我正在尝试遍历电子邮件地址列表并将日志文件发送到每个..

任何其他信息都会很棒!

首先,文件顶部有一个var数组:

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() & "  -  " & 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

2 个答案:

答案 0 :(得分:0)

undefined var在哪一行?或者什么是var名称?

无论哪种方式,'strLogText'都没有在任何地方定义。此外,如果这是一个经典的ASP页面,则在顶部放置一个Option Explicit语句。

答案 1 :(得分:0)

您似乎无法在任何地方呼叫getEmailAddresses(),因此您的文件将无法读取,并且您的emails数组将不会被填充