VBScript中的数组定义差异
我试图通过VBscript使用ANSYS Maxwell脚本,但数组定义有问题VBScript中的数组定义差异,vbscript,Vbscript,我试图通过VBscript使用ANSYS Maxwell脚本,但数组定义有问题 oModule.EditSetup "ParametricSetup1", Array("NAME:ParametricSetup1", "IsEnabled:=", _ true, Array("NAME:ProdOptiSetupDataV2", "SaveFields:=", false, "Co
oModule.EditSetup "ParametricSetup1", Array("NAME:ParametricSetup1", "IsEnabled:=", _
true, Array("NAME:ProdOptiSetupDataV2", "SaveFields:=", false, "CopyMesh:=", false, "SolveWithCopiedMeshOnly:=", _
false), Array("NAME:StartingPoint"), "Sim. Setups:=", Array("Setup1"), Array("NAME:Goals", _
_
Array("NAME:Goal", "ReportType:=", "Transient", "Solution:=", _
"Setup1 : Transient", Array("NAME:SimValueContext", "Domain:=", "Sweep"), "Calculation:=", _
Goals(i), "Name:=", "Goal" & cstr(i), Array("NAME:Ranges", "Range:=", Array("Var:=", _
"Time", "Type:=", "a"))), _
Array("NAME:Goal", "ReportType:=", "Transient", "Solution:=", _
"Setup1 : Transient", Array("NAME:SimValueContext", "Domain:=", "Sweep"), "Calculation:=", _
"avg(100 - Efficiency)", "Name:=", "Efficiency", Array("NAME:Ranges", "Range:=", Array("Var:=", _
"Time", "Type:=", "a"))), _
Array("NAME:Goal", "ReportType:=", "Transient", "Solution:=", _
"Setup1 : Transient", Array("NAME:SimValueContext", "Domain:=", "Sweep"), "Calculation:=", _
"avg(MassTotal)", "Name:=", "MassTotal", Array("NAME:Ranges", "Range:=", Array("Var:=", _
"Time", "Type:=", "a"))), _
Array("NAME:Goal", "ReportType:=", "Transient", "Solution:=", _
"Setup1 : Transient", Array("NAME:SimValueContext", "Domain:=", "Sweep"), "Calculation:=", _
"max(PhaseVoltage)", "Name:=", "PhaseVoltage", Array("NAME:Ranges", "Range:=", Array("Var:=", _
"Time", "Type:=", "a"))), _
Array("NAME:Goal", "ReportType:=", "Transient", "Solution:=", _
"Setup1 : Transient", Array("NAME:SimValueContext", "Domain:=", "Sweep"), "Calculation:=", _
"max(TorqueRipple)", "Name:=", "TorqueRipple", Array("NAME:Ranges", "Range:=", Array("Var:=", _
"Time", "Type:=", "a"))), _
Array("NAME:Goal", "ReportType:=", "Transient", "Solution:=", _
"Setup1 : Transient", Array("NAME:SimValueContext", "Domain:=", "Sweep"), "Calculation:=", _
"avg(st_length)", "Name:=", "StackLength", Array("NAME:Ranges", "Range:=", Array("Var:=", _
"Time", "Type:=", "a"))), _
Array("NAME:Goal", "ReportType:=", "Transient", "Solution:=", _
"Setup1 : Transient", Array("NAME:SimValueContext", "Domain:=", "Sweep"), "Calculation:=", _
"avg(L_q)/avg(L_d)", "Name:=", "Saliency", Array("NAME:Ranges", "Range:=", Array("Var:=", _
"Time", "Type:=", "a")))))
这段代码是通过ANSYS自动生成的,效果很好,但是,我想通过VBS中的变量给出目标,所以我写了这段代码
Dim ArrS : ArrS = ArraySize + 1
Dim ANSYSGoals()
Redim ANSYSGoals(ArrS)
ANSYSGoals(0) = "NAME:Goals"
For i = 1 to ArraySize Step 1
ANSYSGoals(i) = Array("NAME:Goal", "ReportType:=", "Transient", "Solution:=", _
"Setup1 : Transient", Array("NAME:SimValueContext", "Domain:=", "Sweep"), "Calculation:=", _
Goals(i-1), "Name:=", "Goal" & cstr(i-1), Array("NAME:Ranges", "Range:=", Array("Var:=", _
"Time", "Type:=", "a")))
Next
oModule.EditSetup "ParametricSetup1", Array("NAME:ParametricSetup1", "IsEnabled:=", _
true, ANSYSGoals)
虽然ANSYS接受这种数组(我有一个做类似事情的代码,但代码可以工作),但这段代码不起作用。但是,如果我将代码更改为:
Dim ArrS : ArrS = ArraySize + 1
Dim ANSYSGoals()
Redim ANSYSGoals(ArrS)
ANSYSGoals(0) = "NAME:Goals"
For i = 1 to ArraySize Step 1
ANSYSGoals(i) = Array("NAME:Goal", "ReportType:=", "Transient", "Solution:=", _
"Setup1 : Transient", Array("NAME:SimValueContext", "Domain:=", "Sweep"), "Calculation:=", _
Goals(i-1), "Name:=", "Goal" & cstr(i-1), Array("NAME:Ranges", "Range:=", Array("Var:=", _
"Time", "Type:=", "a")))
Next
oModule.EditSetup "ParametricSetup1", Array("NAME:ParametricSetup1", "IsEnabled:=", _
true, Array(ANSYSGoals(0),ANSYSGoals(1),ANSYSGoals(2)))
它起作用了。因此,我的问题是3项数组ANSYSGoals
和数组(ANSYSGoals(0)、ANSYSGoals(1)、ANSYSGoals(2))之间的区别是什么
提前感谢您的回答。区别在于后者是另一个围绕现有数组的Array()
包装器。我想通过ArraySize变量指定数组的大小,使用该包装器会产生问题,那么我应该应用什么样的解决方案呢?