本文介绍了从Visual Studio Debugger中调用VBScript代码的问题与从命令行调用相同脚本的问题相比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 当我使用调试"从Visual Studio中调用vbscript时出现问题->启动操作工具,选择启动外部程序,然后从那里调用cscript.exe并传递命令行参数 PROCESSXMLMESSAGEFILE.VBS IN \ INXML \ InwardsOrder TQ MCCAIN在直接命令行中调用相同的vbscript并传递相同的命令行参数会产生不同的结果这是vbscript代码-存储在PROCESSXMLMESSAGEFILE.vbs中设置argList = WScript.Arguments custref = UCASE(arglist.Item(2))'custref ='MCCAIN'暗淡FileListSource昏暗的oFileSource设置oFSO = CreateObject("Scripting.FileSystemObject")设置oFileSource = oFSO.GetFile("c:\ TESTONLY \ TQMCCAIN.xml") MsgBox"oFileSource.Name" & oFileSource.Name& "custref" &客户咨询"Instr(1,oFileSource.Name,custref)" & Instr(1,oFileSource.Name,custref)当我将custref更改为硬代码文本"MCCAIN"时,或当我更改"MCCAIN"的位置时因此在命令行列表中将其设置为1(PROCESSXMLMESSAGEFILE.VBS IN \ INXML \ InwardsOrder MCCAIN TQ MCCAIN)在两种情况下均有效,但是当我从arglist.Item(2)中选取它时 因此,(PROCESSXMLMESSAGEFILE.VBS IN \ INXML \ InwardsOrder TQ MCCAIN)在Visual Studio中不起作用....事实上,这使我想知道arglist()是否没有正确地考虑将参数包括或不包括VBS名称......,我认为这是关键........ Instr几乎是一条红鲱鱼,除了我无法解释它如何正确设置 custref的值(显然在arglist.Item(2)行,但随后在Instr行中似乎已将其忘记了(但仅在Instr调用中!!?!问题围绕在oFileSource.Name中找到字符串custref从Visual Studio调试器内部运行相同的代码,说在oFileSource.Name中不存在MCCAIN的情况-但直接从命令行运行总是可以正确找到它一个人解决了这个问题,谢谢任何人答复如果我两次传递第二个参数并坚持使用arglist.Item(2),则在两种情况下都可以使用 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!! 11Steve Giergiel 解决方案 Problem is seen when I call a vbscript from within Visual Studio Using the Debug - > Start Action facility and selecting the Start external Program and calling cscript.exe from there and passing in command line argumentsPROCESSXMLMESSAGEFILE.VBS IN\INXML\InwardsOrder TQ MCCAINcalling the same vbscript from a direct command line passing in same command line arguments gives different resultsHere's the vbscript code - stored within PROCESSXMLMESSAGEFILE.vbsSet argList = WScript.Argumentscustref = UCASE(arglist.Item(2))'custref = "MCCAIN"Dim FileListSourceDim oFileSourceSet oFSO = CreateObject("Scripting.FileSystemObject")Set oFileSource = oFSO.GetFile("c:\TESTONLY\TQMCCAIN.xml")MsgBox "oFileSource.Name" & oFileSource.Name & "custref" & custref & "Instr(1,oFileSource.Name , custref)" & Instr(1,oFileSource.Name , custref)when I change custref to hard code text "MCCAIN" or when I change the position of "MCCAIN" in the command line list to 1 thus(PROCESSXMLMESSAGEFILE.VBS IN\INXML\InwardsOrder MCCAIN TQ MCCAIN)  it works in both cases, but when I pick it up from arglist.Item(2) thus(PROCESSXMLMESSAGEFILE.VBS IN\INXML\InwardsOrder TQ MCCAIN) it does not work in Visual Studio....In fact that lead me to wonder if the arglist() was not properly considering the arguments as including or not including the VBS name ...... and I think that's the key ........ Instr is almost a red herring, except I cant explain how it correctly sets the value of custref (apparently at the arglist.Item(2) line but then in the Instr line it seems to have forgotten it (but only in the Instr call?!?!Problem revolved around the finding of the string custref within oFileSource.NameRunning the same code from Inside Visual Studio Debugger, says that MCCAIN not there in the oFileSource.Name when it is - but running directly from the command line always finds it correctlySOLVED THIS ONE BY MYSELF THANKS TO ANYONE replyingIf I pass the second argument twice and stick with arglist.Item(2) it works in both scenarios!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!11Steve Giergiel 解决方案 这篇关于从Visual Studio Debugger中调用VBScript代码的问题与从命令行调用相同脚本的问题相比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-11 13:06