rbas85
Structural
- Sep 23, 2019
- 7
Dears, I'm trying to translate my vba for excel macro in VB.NET. Hear goes a snippet of my code in VB.NET:
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim App As femap.model
App = GetObject(, "femap.model")
Dim cgXYZ As Object
Dim aux(3) As Double
Dim cgTXYZ(3) As Double
Dim PosIniModelX, Conversor, Mass, MassT, x, y, z As Double
Dim olel As femap.Set
olel = App.feSet
Dim el As femap.Elem
el = App.feElem
Dim elID, grID, rc As Long
grID = ReturnNumber(ComboBox1.Text)
rc = olel.AddGroup(femap.zDataType.FT_ELEM, grID)
Conversor = 1000
PosIniModelX = 0
elID = olel.First()
MassT = 0
Do While elID > 0
rc = el.Get(elID)
rc = el.GetFaceArea(0, Mass)
rc = el.GetCentroid(cgXYZ) <-- I'm having problems hear. Apparently is an object array, but I don't know how to declarate it
x = cgXYZ(0) / Conversor + PosIniModelX
y = cgXYZ(1) / Conversor
z = cgXYZ(2) / Conversor
MassT = MassT + Mass / 10000
aux(0) = aux(0) + x * Mass / 10000
aux(1) = aux(1) + y * Mass / 10000
aux(2) = aux(2) + z * Mass / 10000
elID = olel.Next()
Loop
MassT = MassT
aux(0) = aux(0) / MassT
aux(1) = aux(1) / MassT
aux(2) = aux(2) / MassT
cgTXYZ(0) = aux(0)
cgTXYZ(1) = aux(1)
cgTXYZ(2) = aux(2)
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim App As femap.model
App = GetObject(, "femap.model")
Dim cgXYZ As Object
Dim aux(3) As Double
Dim cgTXYZ(3) As Double
Dim PosIniModelX, Conversor, Mass, MassT, x, y, z As Double
Dim olel As femap.Set
olel = App.feSet
Dim el As femap.Elem
el = App.feElem
Dim elID, grID, rc As Long
grID = ReturnNumber(ComboBox1.Text)
rc = olel.AddGroup(femap.zDataType.FT_ELEM, grID)
Conversor = 1000
PosIniModelX = 0
elID = olel.First()
MassT = 0
Do While elID > 0
rc = el.Get(elID)
rc = el.GetFaceArea(0, Mass)
rc = el.GetCentroid(cgXYZ) <-- I'm having problems hear. Apparently is an object array, but I don't know how to declarate it
x = cgXYZ(0) / Conversor + PosIniModelX
y = cgXYZ(1) / Conversor
z = cgXYZ(2) / Conversor
MassT = MassT + Mass / 10000
aux(0) = aux(0) + x * Mass / 10000
aux(1) = aux(1) + y * Mass / 10000
aux(2) = aux(2) + z * Mass / 10000
elID = olel.Next()
Loop
MassT = MassT
aux(0) = aux(0) / MassT
aux(1) = aux(1) / MassT
aux(2) = aux(2) / MassT
cgTXYZ(0) = aux(0)
cgTXYZ(1) = aux(1)
cgTXYZ(2) = aux(2)
End Sub