New Operator

Use the New operator to instantiate objects of user-defined types, as well as Uno services, structs and enumerations.


Dim oObj as New ObjectType

oObj = New ObjectType


The New operator can be used either during variable declaration or in an assignment operation.


The following example uses the New operator to create an instance of the PropertyValue Uno struct.

    ' Instantiating the object during variable declaration
    Dim oProp1 as New
    oProp1.Name = "Some name"
    oProp1.Value = 100
    ' The same can be accomplished with an assignment
    Dim oProp2 as Object
    oProp2 = New
    oProp2.Name = "Other name"
    oProp2.Value = 200

New operator is optional when setting Option Compatible option.

The example below creates a new type Student and instantiates an object of this type:

    Type Student
        FirstName as String
        Program as String
    End Type
    Sub TestObjects
        Dim oStudent1 as New Student
        oStudent1.FirstName = "John"
        oStudent2.Program = "Computer Science"
    End Sub

Please support us!