VBS使用LIKE比较字符串“Sub or Function not defined" [英] VBS using LIKE to compare strings "Sub or Function not defined"
问题描述
我正在尝试编写一个脚本来将网络打印机连接到用户计算机.该脚本使用需要打印机的计算机名称作为参数.
I'm trying to make a script to connect a network printer to a user computer. The script uses the computer name who needs the printer as a parameter.
打印机名称与其打印服务器名称相似,例如.server_USA 有打印机,如 printer_USA01、printer_USA02.
Printers names are similar their printserver name, eg. server_USA has printers like printer_USA01, printer_USA02.
但是它在到达第一个时抛出错误Sub or Function not defined",就像......为什么?
But it's throwing the error "Sub or Function not defined" when arrives at the first like... why ?
Set shl = WScript.CreateObject("WScript.Shell")
strName = Wscript.Arguments.Item(0)
'input Printer name
strPrinter = InputBox("Please enter share name of printer to install:", _
"Add network printer")
if strPrinter = "" then
msgbox "Can't be empty."
WScript.quit
elseif strPrinter Like "printer_USA*" then
strServer = server_USA
elseif strPrinter Like "printer_SPAIN*" then
strServer = server_SPAIN
else
'Printer name NOT registered, input printserver manually:
strServer = inputbox("Please enter the name of the printserver","printserver")
if strServer = "" then
msgbox "Can't be empty."
WScript.quit
End if
End if
'ADD
shl.run "RUNDLL32 PRINTUI.DLL,PrintUIEntry /ga /c\\" & strName & " /n\\" & strServer & "\" & strPrinter
推荐答案
VBScript 中没有 Like 运算符.您可以使用 Instr.
there is no Like operator in VBScript. You could use Instr.
if strPrinter = "" then
msgbox "Can't be empty."
WScript.quit
elseif Instr( 1, strPrinter, "printer_USA", vbTextCompare ) > 0 then
strServer = server_USA
vbTextCompare 常量 (value=1) 用于执行文本比较
The vbTextCompare constant ( value=1) is used to Perform a textual comparison
这篇关于VBS使用LIKE比较字符串“Sub or Function not defined"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!