我正在处理向ETABS 2016提供某些数据的Excel VBA模块,部分代码是使用API方法SetMaterial
和SetOConcrete_1
定义多个材料属性。
代码的有效部分是这个
'Values:-
'Val(0)=label, Val(1)=Fc', Val(2)=E, Vals(3)=StrainAtFc, Val(4)=UltimateStrain, Val(5)=PoisonRatio, Val(6)=Thermal Coef
'Val(7) = UnitWeight
For i = 0 To iCount - 1
.
.
SOME LONG CODE TO RETRIEVE DATA TO A DYNAMIC ARRAY OF VARIANTS CALLED "VAL"
.
.
With myModel.PropMaterial
MsgBox Val(0) & " " & Val(1) & " " & i 'debug line to display input values for label and FC'
ret = .SetMaterial(Val(0), eMatType_Concrete)
ret = .SetOConcrete_1(Val(0), Val(1), False, 0, 2, 4, Val(3), Val(4), -0.1)
ret = .SetWeightAndMass(Val(0), 1, Val(7))
ret = .SetMPIsotropic(Val(0), Val(2), Val(5), Val(6))
End With
Next i
我甚至添加了一个调试部件来显示感兴趣的值,每个定义,两个定义等等,这部分是
'Debugging part
If i >= 0 Then
On Error GoTo 0
Err.Raise (2)
End If
'End of Debugging part
然后,我将i >= 0
更改为i >= 1
并更改为i >= 2
以显示所需的迭代次数。
调试部分始终为每次迭代显示Val(0)
(材料的名称)和Val(1)
(材料的Fc)的正确和所需值,
例如,每次迭代的值为: -
1-迭代1:Val(0) = "C35"
,Val(1) = 35000
,i = 0
2-迭代2:Val(0) = "C37"
,Val(1) = 37000
,i = 1
3-迭代3:Val(0) = "C38"
,Val(1) = 38000
,i = 2
然后,ETABS中发生的情况如下: -
1-使用i >= 0
我得到一个迭代和一个材料定义" C35"," C35"有Fc = 35MPa [正确结果]
2-使用i >= 1
我得到两个迭代和两个材料定义" C35"和#34; C37",但所有这些都有Fc = 37 MPa [错误的结果]
3-使用i >= 2
我得到三次迭代和三种材料定义" C35"," C37"和" C38",但所有这些都有Fc = 38 MPa [错误的结果]
那么,在每次迭代时,材料的名称和Fc到SetOConcrete_1
的提供值如何能够不同,ETABS只是忽略所有工作,只提供所有材料的最后一个Fc值? !
答案 0 :(得分:0)
ETABS API是否将您提供的值作为参考?根据你的解释,这就是它的样子。
Public Sub Temp()
'In order to use early-binding Dictionary you need to set a
'reference in Tools>References>"Microsoft Scripting Runtime"
Dim foo As Dictionary
Set foo = New Dictionary
Dim bar As Range
Set bar = ActiveSheet.Range("A1")
bar.Value2 = "Original"
foo.Add "1", bar.Value2
foo.Add "2", bar
bar.Value2 = "Changed"
Debug.Print foo("1")
Debug.Print foo("2")
End Sub
如果您浏览此示例,您会注意到当项目添加了.Value2
值类型时,它不会更改。当它作为Range
引用类型输入时,它将会改变。
如果您将Val
变量中的每个值提取到各自的类型中,然后将它们输入,则可能会有不同的结果。
Dim label As String
label = Val(0)
Dim Fc As Long
Fc = Val(1)
Dim strainAtFc As Long
strainAtFc = Val(3)
Dim ultimateStrain As Long
ultimateStrain = Val(4)
Dim poisonRatio As Long
poisonRatio = Val(5)
Dim thermalCoefficient As Long
thermalCoefficient = Val(6)
Dim unitWeight As Long
unitWeight = Val(7)
***请注意,Val
也是VBA.Conversion的成员,如果不是Dim
d,可能会导致问题。