VBScript 是否允许在函数调用中使用命名参数? [英] Does VBScript allow named arguments in function calls?

查看:31
本文介绍了VBScript 是否允许在函数调用中使用命名参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在 VBScript 中运行以下代码,但它没有编译最后一条语句.是不是因为 VBScript 不允许命名参数?

I am trying to run the following code in VBScript but it is not compiling the last statement. Is it because VBScript doesn't allow named arguments?

Filename_Argument = WScript.Arguments(0)
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook = objExcel.Workbooks.Add()
Workbooks.OpenText Filename:=Filename_Argument, Origin _
        :=xlMSDOS, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
        xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False _
        , Comma:=False, Space:=False, Other:=True, OtherChar:="|", FieldInfo _
        :=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), _
        Array(7, 1), Array(8, 1)), TrailingMinusNumbers:=True

推荐答案

VBScript 不支持过程和函数的命名参数.您需要将参数列表更改为位置:

VBScript doesn't support named arguments to procedures and functions. You need to change the argument list to positional:

Workbooks.OpenText Filename_Argument, xlMSDOS, ...

VBScript 也无法识别 Excel 常量(如 xlMSDOS),因此您需要查找它们并用它们的数值替换它们:

VBScript also doesn't recognize Excel constants (like xlMSDOS), so you need to look them up and replace them with their numeric values:

Workbooks.OpenText Filename_Argument, 3, ...

并且您必须使用显式对象引用:

And you must use explicit object references:

objExcel.Workbooks.OpenText Filename_Argument, 3, ...

Excel 宏记录器将命名参数按位置顺序排列,因此您只需删除参数名称即可.不想指定的可选参数可以省略,例如:

The Excel Macro Recorder puts named arguments into positional order, so you can just delete the parameter names. Optional parameters that you don't want to specify can be omitted, e.g.:

x = Function(Var1, , Var3)
'                 ^
'                 `- omitted optional 2nd parameter

这篇关于VBScript 是否允许在函数调用中使用命名参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆