传递Int和List变量给VBscript

本文关键字:VBscript 变量 List Int 传递 | 更新日期: 2023-09-27 18:09:57

我正在使用process.StartInfo.Arguments从我的c#代码传递变量到我的VBscript,但它只传递字符串变量。

这是我的示例代码,它确实可以传递字符串。

System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.FileName = "E:''Libraries''Document''Merge.vbs";
process.StartInfo.WorkingDirectory = "E:''Libraries''Document''";
process.StartInfo.Arguments = FileName;
process.Start();

我怎么可能通过intList<string>到我的VBscript不使用startinfo.Arguments ?

传递Int和List变量给VBscript

参数总是字符串值,您需要将它们转换为字符串以便传递它们。

例如,可以使用string.Join

来翻译列表
int myInt
List<string> myStringList;
List<int> myIntList;
string intAsString = myInt.ToString();
string stringListAsString = string.Join(",",myStringList);
// using System.Linq
string stringListAsString = string.Join(",",myIntList.Select(x => x.ToString());

要解码另一端,假设您已经将参数复制到匹配的变量中,则需要split函数。

myInt = CInt(intAsString)
myStringList = Split(stringListAsString,",")
myIntList = Split(intListAsString,",")
for a = LBound(myIntList) to Ubound(myIntList)
  myIntList(a) = CInt(myIntList(a))
next a

如果参数的剪切量太大,您可以将它们写入临时文件并将文件名传递到VB脚本

这不是这样工作的。程序的参数总是字符串。这意味着你必须将所有参数转换为字符串并在你的vbscript

中解析它们