【问题标题】:VBScript Error code 800A0409, Unterminated string constant, on line 1VBScript 错误代码 800A0409,未终止的字符串常量,在第 1 行
【发布时间】:2014-07-17 20:35:18
【问题描述】:

我在第 1、54 行收到错误代码 800A0409,未终止的字符串常量,代码如下。

Option Explicit

Dim ObjProgressMsg
Dim fso,objText,strVstup,strVystup,f,dtmVyt,dtmF,dDiff,fName,fExt,fShort,dtmAkt,tx,msgText
Dim strMessage,strWindowTitle,strTemp,wshShell,objTempMessage,strTempVBS


Set fso = CreateObject("Scripting.FileSystemObject") 
Set objText = fso.GetFile("l:\bat\posledni.den")
strVstup = "l:\filefolder\"
strVystup = "l:\backup"

dtmVyt = objText.DateLastModified

msgText = "Some text about copying and renaming" & VbCrLf & "files, please wait..."

ProgressMsg msgText

For Each f In fso.GetFolder(strVstup).Files

    dtmF = f.DateLastModified

    dDiff = DateDiff("s", dtmF, dtmVyt)

    If dDiff < 0 Then
          ProgressMsg ""
          WScript.Echo f
    End If

Next

WScript.Echo "Some text about the task being finished."




Function ProgressMsg( strMessage )
' Written by Denis St-Pierre
' Displays a progress message box that the originating script can kill in both 2k and XP
' If StrMessage is blank, take down previous progress message box
' Using 4096 in Msgbox below makes the progress message float on top of things
' CAVEAT: You must have   Dim ObjProgressMsg   at the top of your script for this to work as described
    Set wshShell = WScript.CreateObject( "WScript.Shell" )
    strTEMP = wshShell.ExpandEnvironmentStrings( "%TEMP%" )
    If strMessage = "" Then
        ' Disable Error Checking in case objProgressMsg doesn't exists yet
        On Error Resume Next
        ' Kill ProgressMsg
        objProgressMsg.Terminate( )
        ' Re-enable Error Checking
        On Error Goto 0
        Exit Function
    End If
        strTempVBS = strTEMP + "\" & "Message.vbs"     'Control File for reboot

    ' Create Message.vbs, True=overwrite
    Set objTempMessage = fso.CreateTextFile( strTempVBS, True )
    objTempMessage.WriteLine( "MsgBox""" & strMessage & """, 4096, """ & "a_sp_rano" & """" )
    objTempMessage.Close

    ' Disable Error Checking in case objProgressMsg doesn't exists yet
    On Error Resume Next
    ' Kills the Previous ProgressMsg
    objProgressMsg.Terminate( )
    ' Re-enable Error Checking
    On Error Goto 0

    ' Trigger objProgressMsg and keep an object on it
    Set objProgressMsg = WshShell.Exec( "%windir%\system32\wscript.exe " & strTempVBS )

End Function

在搜索比 posledni.den 文件的最后修改日期更新的文件时,该脚本应显示一个 msgbox。然后一旦它找到一个文件,它应该关闭 msgbox 并回显它找到的文件。 如果我改变它就可以了:

msgText = "Some text about copying and renaming" & VbCrLf & "files, please wait..."

到这里:

msgText = "Some text about copying and renaming" & "files, please wait..."

删除 VbCrLf 似乎可以解决该错误,只是显然没有发生换行符。我不知道为什么它会这样,我做错了什么。对这个问题的每一种见解都将不胜感激。

提前谢谢你。 :)

【问题讨论】:

    标签: vbscript


    【解决方案1】:

    在执行生成的.vbs 时发生错误。你要做的是:

    >> msg1 = "A" & vbCrLf & "B"
    >> code = "MsgBox """ & msg1 & """"
    >> WScript.Echo code
    >>
    MsgBox "A
    B"
    >> Execute code
    >>
    Error Number:       1033
    Error Description:  Unterminated string constant
    

    你应该做什么:

    >> msg1 = """A"" & vbCrLf & ""B"""
    >> WScript.Echo msg1
    >>
    "A" & vbCrLf & "B"
    >> code = "MsgBox " & msg1 & ", 4096"
    >> WScript.Echo code
    >>
    MsgBox "A" & vbCrLf & "B", 4096
    >> Execute code
    >>
    >> <-- no news are good news; message displayed
    

    【讨论】:

    • 完美,我现在可以看到了。当这些双引号堆积起来时,我总是会感到困惑。非常感谢! :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-01
    • 2011-04-27
    相关资源
    最近更新 更多