8. March 2022

INOSIM 13 – WWB.NET vs. WWB-COM

With the INOSIM 13 Version, the Basic Editor supports, in addition to WWB-COM, the WWB.NET language, which is compatible with Visual Basic .NET. Therefore, also .NET libraries can be used within INOSIM. In the new INOSIM version, WWB.NET is now used as the default language rather than WWB-COM.

The default language determines the language which is used in a newly inserted Macro. Existing Macros are not changed. In the first line of code the language setting is displayed:


Macro with WWB-COM


Macro with WWB.NET

Changing the code in the first line, changes the language that is used. In the INOSIM Basic editor, the default language for new Macros can be set via: Tools > Options:

Please note that there are some differences using WWB.NET in comparison to WWB-COM! In the following, the main differences are explained.

Set Statement

In WWB-COM, Set is needed to assign objects. This instruction is not needed in WWB.NET. The object assignment is working like other assignments with a simple equal sign.

In this example, a production order is created during the initialization stage of the simulation. The assignment of the recipe, the material, and the order to the order variable need a Set because they are considered objects.

'#Language "WWB-COM"
Set o = New Order 'set because an object is assigned
o.Name = "Order"
Set o.Recipe = Recipes("Production (V1)") 'set because an object is assigned
Set o.Material = Materials("Produkt") 'set because an object is assigned
Orders.Add o

'#Language "WWB.NET"
o = New Order
o.Name = "Order"
o.Recipe = Recipes("Production (V1)")
o.Material = Materials("Produkt")
Orders.Add o

Events like Simulation_Init

For subroutines (Subs) that handle certain events, the handled event must be specified explicitly. Examples for such Subs are the initialization of the simulation and the EndSim, the end of the simulation.

For the initialization, the code in WWB.NET changes in comparison to WWB-COM as follows. Thanks to the explicit specification of the event, it is possible to rename the subroutine in WWB.NET.

'#Language "WWB-COM"
Private Sub Simulation_Init()

End Sub

'#Language "WWB.NET"
Private Sub Simulation_Init() Handles Simulation.Init
    
End Sub

IsEmpty/IsNull/IsObject

The functions IsEmpty, IsNull, and IsObject do not exist in WWB.NET. With IsEmpty in WWB-COM, it is possible to ask if there has already been a value assigned to a variable of type Variant. If no value has been assigned, then the IsEmpty function returns the value False. In WWB.NET, the Type Variant does not exist, so the function is not needed anymore.

With the function IsNull in WWB-COM, you can determine if something is null (not 0). Entries in dictionaries and table objects to which no value has been assigned are null. This is also relevant for Custom Attributes, as this property is a dictionary. If you generate a Custom Attribute in VBA and no value has been assigned yet, its value is null. To determine in WWB.NET if a value is null, the function IsDBNull can be used:

'#Language "WWB-COM"
If IsNull(Units("Tank 1").CustomAttributes("Diameter")) Then
    Units("Tank 1").CustomAttributes("Diameter") = 3
End If

'#Language "WWB.NET"
If IsDBNull(Units("Tank 1").CustomAttributes("Diameter")) Then
    Units("Tank 1").CustomAttributes("Diameter") = 3
End If

The function IsObject returns the value True if the asked variable is an object. In WWB.NET, this is done with the function IsReference:

'#Language "WWB-COM"
If IsObject(Units("Tank 1")) Then
      'True
End If

'#Language "WWB.NET"
If IsReference(Units("Tank 1")) Then
      'True
End If

Enum

An Enum is a value type that is used in INOSIM for variables for which only a certain set of constants is allowed. A typical example in INOSIM is the OperationState which specifies the state of an operation. The OperationState can be bOpOpen, bOpStarting, bOpStarted, bOpFinished, or bOpCancelled.

In WWB.NET, in addition to the Enum value, the Enum name has to be specified when assigning the constant.

In this example, the new Unit Pool Allocation control from INOSIM 13 is used (see Using the new controls for Unit Pools in INOSIM 13). The Enum PendingUnitMode is used to decide which unit from a pool should be allocated. In the example, only Tank 1 should be used.

'#Language "WWB-COM"
Sub Pool_Allocation(proc As ProcedureInstance, p As UnitPool, u As Unit, ByRef allocate As Boolean)
    
    Dim pm As Unit
    If u Is Nothing Then 'identifies the first call of the control 
        For Each pm In p.Members
            If pm.Name="Tank 1" Then
                proc.PendingUnitsMode(pm.Name) = puAllocate
            Else
                'all other tanks are ignored
                proc.PendingUnitsMode(pm.Name) = puIgnore
            End If
        Next
    End If

End Sub


'#Language "WWB.NET"
Sub Pool_Allocation (proc As ProcedureInstance, p As UnitPool, u As Unit, ByRef allocate As Boolean)
    
    Dim pm As Unit
    If u Is Nothing Then
        'identifies the first call of the control
        For Each pm In p.Members
            If pm.Name="Tank 1"Then
                proc.PendingUnitsMode(pm.Name) = PendingUnitMode.puAllocate
            Else
                proc.PendingUnitsMode(pm.Name) = PendingUnitMode.puIgnore
                'all other tanks are ignored
            End If
        Next
    End If

End Sub

Variants and Arrays

In WWB.NET, the variable type Variant does not exist. As an alternative, variables can be declared as Object. Arrays that are usually declared as Variant in WWB-COM can be declared as Object arrays in WWB.NET. It is also possible to use lists in WWB.NET to save more than just a single value in one variable. In the following example, the values from an Excel sheet are saved in an array. Afterwards, the first value of the array is printed to the console.

'#Language "WWB-COM"
Private Sub Simulation_Init()
    Dim n_rows As Integer
    Dim n_columns As Integer
    n_rows=Parameters.Sheets("Sheet").LastRow 'number of last used row in Excel sheet
    n_columns=Parameters.Sheets("Sheet").LastColumn 'number of last used column in Excel sheet

    Dim a As Variant 'array as variant
    ReDim a (n_rows,n_columns) As Object 'sizing of dimensions
    a=Parameters.Sheets("Sheet").RangeYX(1,1,no_rows,no_columns) 'Read in values for array from Excel sheet

    Console.Print a(1,1) 'Print out the first value in the console
End Sub

'#Language "WWB.NET"
Private Sub Simulation_Init() Handles Simulation.Init
    Dim n_rows As Integer
    Dim n_columns As Integer
    n_rows=Parameters.Sheets("Sheet").LastRow 'number of last used row in Excel sheet
    n_columns=Parameters.Sheets("Sheet").LastColumn 'number of last used column in Excel sheet

    Dim a (,) As Object 'number of dimensions defined by comma
    ReDim a (n_rows,n_columns) As Object 'sizing of dimensions
    a=Parameters.Sheets("Sheet").RangeYX(1,1,no_rows,no_columns) 'Read in values for array from Excel sheet

    Console.Print a(1,1) 'Print out the first value in the console
End Sub

Data Types

In WWB.NET, the boundaries for Long and Double values are wider. Additionally, the data type, Short, for integer values is available:

Data Type WWB.NET WWB-COM
Short – 32,768 to 32,767
Integer -2.15 E+18 to 2.15 E+18 – 32,768 to 32,767
Long – 9.2 E+18 to 9.2 E+18 -2.15 E+18 to 2.15 E+18

Downloads

(for registered INOSIM users)

  • PDF printout of this Tip & Trick

More Questions?

Want to know more about this topic or have another question? Please contact us!

Array ( [posts_per_page] => 3 [post_type] => [category__in] => Array ( [0] => 36 ) [orderby] => rand [order] => ASC )

More Tips & Tricks

2. September 2022

Tank Level Evaluation

INOSIM provides a set of predefined results and evaluations, either in the Gantt Chart or as an Excel Report. Especially the Excel Reports can be…

This Tip & Trick describes a multitude of methods to prevent and handle runtime errors of your VBA code. You will be introduced to the…

With the INOSIM 13 Version, the Basic Editor supports, in addition to WWB-COM, the WWB.NET language, which is compatible with Visual Basic .NET. Therefore, also…

more

Direct Contact

During local business hours

Germany +49 231 97 00 250

USA +1 214 663 3101

India +91 9766 331 092