Ept*_*tin 3 import vbscript invalid-characters character-encoding importerror
我在VBscript中遇到"无效字符"错误!特别是在这段代码中:
'*******************************************************************
'Import Code
'by Cheyne Wallace
'November 2008
'When using only VBscript (not QTP), this code will import any function library passed into it.
'Copy this function into a file, then use it to bring in various other function libraries.
'Usage:
' Import "Library.vbs"
Sub Import(strFile)
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim wss : Set wss = CreateObject("WScript.Shell")
strFile = wss.ExpandEnvironmentStrings(strFile)
strFile = objFSO.GetAbsolutePathName(strFile)
Set objFile = objFSO.OpenTextFile(strFile, 1)
ExecuteGlobal objFile.ReadAll
objFile.Close : Set objFSO = nothing
Set wss = Nothing
End Sub
Run Code Online (Sandbox Code Playgroud)
错误状态" Microsoft VBScript compilation error. Invalid Character. Code: 800A0408"在Char:2,206行上,这是第一个字母ExecuteGlobal objFile.ReadAll(字符1是一个标签).
我输入并重新输入了该线以及周围的换行符.不过,它一直在说"无效的角色".到底是怎么回事??
事实证明,问题不在于ExecuteGlobal,而是使用我尝试导入的.vbs文件.我导入的文件不是ANSI编码.如果VBScript与您要导入的文件有问题,它将在字符和行的开头报告错误ExecuteGlobal(这无疑会引起混淆).
打开您尝试导入的文件,将其转换为ANSI,一切都应该有效.