I have an issue with the GetMemberEndForces command and the input of member number and load case number. I try to use a variable of type Variant to use an array to be more efficient. The issue is staad always return a value of 0 for my forces. If a do the exact same code, but i store the value of my member number and load case number in a variable of type Long, it work without issue, but make my macro slower. Is there an issue with the command GetMemberEndForces and variable of type Variant ?
Public Sub UpdateForces() Dim objSTAAD As Object Dim ForceConv As Double Dim LengthConv As Double Dim activeMember As Variant Dim LCnumber As Variant
Dim pnResult As Integer Dim pdForces0(6) As Double, pdForces1(6) As Double On Error GoTo erreur Dim DataRange As Variant Dim Irow As Long Dim Icol As Integer DataRange = Range(Range("G16"), Cells(Range("A16").End(xlDown).Row, Range("G9").End(xlToRight).Column)).Value2 activeMember = Worksheets("Axial loads").ListObjects("MemberId").DataBodyRange.Value2 LCnumber = Worksheets("Axial loads").ListObjects("Loadcases").DataBodyRange.Value2
' delete existing tables Selection.ClearContents 'Calculate conversion factor for force unit Select Case Range("B6").Value2 Case "N" ForceConv = 4448.22 Case "kN" ForceConv = 4.44822 Case "MN" ForceConv = 4.44822 / 1000 Case "lbf" ForceConv = 1000 Case "kip" ForceConv = 1 End Select 'Calculate conversion factor for length unit Select Case Range("B7").Value2 Case "mm" LengthConv = 25.4 Case "m" LengthConv = 0.0254 Case "in" LengthConv = 1 Case "ft" LengthConv = 1 / 12 End Select Select Case ActiveSheet.Name Case Is = "Axial loads" For Irow = LBound(DataRange, 1) To UBound(DataRange, 1) For Icol = LBound(DataRange, 2) To UBound(DataRange, 2) objSTAAD.OutPut.GetMemberEndForces activeMember(Irow, 1), 0, LCnumber(1, Icol), pdForces0 objSTAAD.OutPut.GetMemberEndForces activeMember(Irow, 1), 1, LCnumber(1, Icol), pdForces1
If pdForces0(0) >= 0 And -pdForces1(0) >= 0 Then DataRange(Irow, Icol) = ForceConv * Max(pdForces0(0), -pdForces1(0)) Else DataRange(Irow, Icol) = ForceConv * Min(pdForces0(0), -pdForces1(0)) End If Next Icol Next Irow Range(Range("G16"), Cells(Range("A16").End(xlDown).Row, Range("G9").End(xlToRight).Column)) = DataRange End Select GoTo fin End If
erreur: MsgBox (Error(Err.Number)) GoTo finfin: Set objSTAAD = Nothing
End Sub
Variant type will not work. You have to use Long, double or string for the variable as per your requirement for VBA. If you try to run any OpenSTAAD function with null or variant variable type, either it will not work or incorrect results will be extracted. That's why we always suggest to create a variable with proper variable type, assign the value to that variable and then use that variable in the OpenSTAAD function
Answer Verified By: David Archambault
Thanks you ! Were do I find those suggestion, because the help file of staad does say const Variant ?
Let me give you some examples. For VBA,
Perfect, thanks !