# COM Interface in VBA | 4.1 Frame Optimization

### Technical Article

Part 4.1 and 4.2 of this article series describes the optimization of a frame using the RF‑/STEEL EC3 add-on module. The fifth part explains how to link the module and get the relevant members. The elements already explained in the previous parts are not described again.

Figure 01 - System
Dim crsc_desc As String
crsc_desc = "IPE 300"

'Get all cross-sections from RFEM
Dim crscs () As RFEM5.CrossSection
crscs = iModelData.GetCrossSections

'Loop over all cross-sections
Dim crsc_no As Long
crsc_no = -1
Dim i As Long
For i = 0 To UBound (crscs, 1)
'If the cross-section description is correct, save the cross-section number
If InStr (LCase (crscs (i) .Description), LCase (crsc_desc))> 0 Then
crsc_no = crscs (i) .No
Exit For
End If
Next i

'Exit the program if the desired cross-section was not found
If crsc_no = -1 Then
Err.Raise 513, "Get cross-section number", "No cross-section with" "" & crsc_desc & "" within its description found! "
End If

The cross-section description should be compared as generally as possible. To do this, first use "LCase" to set both the cross-section description and the string to be searched for to lower-case letters, and then search for the string in the cross-section description. If no suitable cross-section was found, the cross-section number remains at -1, which can then be queried and canceled.

After this step, the cross-section number is known and the members with this cross-section number can be searched. Only members with this cross-section at the start and end should be transferred:

'Create string for member list and set to zero
Dim mems_str As String
mems_str = vbanullstr

'Get all members from RFEM
Dim mems () As RFEM5.Member
mems = iModelData.GetMembers

'Loop over all members
For i = 0 To UBound (mems, 1)
'If a member has this cross-section number at the beginning and end,
'then its number is transferred to the string
If mems (i) .EndCrossSectionNo = crsc_no Then
If mems (i) .EndCrossSectionNo = mems (i) .StartCrossSectionNo Then
mems_str = mems_str & mems (i) .No & ","
End If
End If
Next i

'End program if no member was found
If mems_str = vbanullstr Then
Err.Raise 514, "Get members", "No member with cross-section" "" & crsc_desc & "" "found!"
End If

#### Get interface of add-on module

The connection to a module is the same as the connection to RFEM or RSTAB. The only difference is that there is no difference between opening an already open instance or opening a new instance because there is always an already open instance:

'Get interface for module
Dim iStec3 As STEEL_EC3.Modules
Set iStec3 = iModel.GetModule ("STEEL_EC3")

Next, we delete all existing module cases:

'Get number of existing module cases
Dim count As Long
count = iStec3.moGetCaseCount

'If cases exist, always delete the first one in the table
If count> 0 Then
For i = 0 To count - 1
iStec3.moDeleteCase i, AT_INDEX
Next i
End If

Then, you can create the desired case and enter the members for the design using the previously created string:

'Create' Optimization 'module case
Dim iStec3Case As STEEL_EC3.ICase
Set iStec3Case = iStec3.moSetCase (1, "Optimization")

'Set members for design
iStec3Case.moSetMemberList mems_str

Finally, enter the desired load case combinations:

'Set load combinations
Dim iStec3_uls_loads (0 To 2) As STEEL_EC3.ULS_LOAD

iStec3_uls_loads (0) .DesignSituation = DS_FUNDAMENTAL
iStec3_uls_loads (0) .No = 1
iStec3_uls_loads (0) .Type = ILOAD_GROUP

iStec3_uls_loads (1) .DesignSituation = DS_FUNDAMENTAL
iStec3_uls_loads (1) .No = 2
iStec3_uls_loads (1) .Type = ILOAD_GROUP

iStec3_uls_loads (2) .DesignSituation = DS_FUNDAMENTAL
iStec3_uls_loads (2) .No = 3
iStec3_uls_loads (2) .Type = ILOAD_GROUP

iStec3Case.moSetULSLoads iStec3_uls_loads

#### Summary and Outlook

The procedures shown here are representative of all modules that can be controlled with COM. The source code and the Excel file help you to understand the topic even better. In the next article, I will go into more depth and create the connection between elements in the module and in the main program.