A Dim/Var Statement creates only one new object at a time

From Xojo Documentation

(Redirected from A Dim Statement creates only one new object at a time)
Error message

You used the optional New operator in a Var statement to instantiate two or more objects. You cannot use the New operator in a Var statement that declares more than one variable. You can, for example, declare multiple variables with the Var statement and then use separate statements to instantiate them. Your other option is to use the optional New operator in separate Var statements.

fa-info-circle-32.png
This error and the explanation of it applies to the Dim statement as well.

Sample Code

The following statement produces this error:

Var n, m As New FolderItem

Either of the following is correct. In the first case, all variables are declared in one statement and instantiated separately.

Var n, m As FolderItem
n = New FolderItem
m = New FolderItem

Using separate Dim statements:

Var n As New FolderItem
Var m As New FolderItem

See Also

Var statement, New operator.