Conteúdo

# New Operator

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

### Sintaxe:

Dim oObj as New ObjectType

oObj = New ObjectType

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

### Exemplo:

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 com.sun.star.beans.PropertyValue
        oProp1.Name = "Some name"
        oProp1.Value = 100
        ' The same can be accomplished with an assignment
        Dim oProp2 as Object
        oProp2 = New com.sun.star.beans.PropertyValue
        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

Tópicos relacionados

Dim Statement

CreateObject Function

Set Statement

Type Statement

Necessitamos da sua ajuda!