Następnie należy podać kod źródłowy prostego programu. Najpierw można utworzyć interfejs modelu, a następnie otworzyć go przy użyciu modelu. Po zapisaniu program zostaje zamknięty.
Obsługa błędów jest zawsze dobra w celu wykrycia i wyświetlenia ewentualnych problemów wejściowych / wyjściowych. W przypadku wystąpienia problemu licencja zostanie odblokowana ponownie, aby umożliwić dostęp do programu RFEM / RSTAB. Więcej informacji na ten temat można znaleźć w kodzie źródłowym.
Sub CreateModel()
' Firstly, an interface' to a new model is created.Dim iModel As RFEM5.model Ustawić iModel = Nowy RFEM5.model
' Here, the model name is defined,
' either the content of cell B2 of sheet Table1
' or, if empty, "test.rf5".
Dim modelName As StringIf IsEmpty(Worksheets( "Table1").Range( "B2").Value) Then modelName = "test01.rf5"Else modelName = CStr(Worksheets( "Tabelle1").Range( "B2").Value) End If
' Transfer of the model name to the interface.iModel.SetName(modelName)
' It is possible to specify a model description here.iModel.SetDescription( "description")
' Error handling routine.On Error GoTo e
Dim iApp As RFEM5.Application ' Interface to the program is opened.
' (Program is started.)
Ustawić iApp = iModel.GetApplication
' COM license and program access are blocked.iApp.LockLicense
' Program is displayed in the foreground.iApp.Show
' Model is saved at "C:\temp" .iModel.Save("C:\temp\" & modelName)
e: If Err.Number <> 0 Then MsgBox Err.Description, , Err.Source
' COM license is unblocked, program access possible again.iModel.GetApplication.UnlockLicense ' Program is closed.iApp.Close
End Sub