Odd syntax error... variant?

This compiles:

Dim v As variant = cluster.Keys
Dim numDimensions as Integer = v(0).Features.Ubound + 1

This does not:

Dim numDimensions as Integer = cluster.Keys(0).Features.Ubound + 1

Wasswrongwitme?

cluster.Keys(0)

The zero is interpreted as an argument to the Keys method rather than as an index into the array the method returns.

Keys is a function that returns an array, it’s not itself an array.

What’s cluster? A dictionary or something else?

cluster is a dictionary.

As Julia said cluster.keys returns an array, so with

Dim v As variant = cluster.keys

I get

This is not an array but you are using it as one
Dim numDimensions As Integer = v(0).Features.Ubound + 1

What Xojo version are you using?

Then I changed v to v(), I don’t get an error but now I get:

Type “Variant” has no member named “Features”
Dim numDimensions As Integer = v(0).Features.Ubound + 1

what is v(0).Features ?

I am using 2019 1.1

Are you answering to me?
I get the exact same errors using Xojo2019r1.1, ‘v’ not an array and when I fix that I get “Variant” has no member named “Features”

This does not compile here:

var cluster As New Dictionary("a":1111, "b":2222)
var v As Variant = cluster.Keys
var numDimensions as Integer = v(0).Features.Ubound + 1
break

1 Like

That should be:

// Arrays are defined using () after the name.
var v() as Variant = cluster.Keys
2 Likes

Seems like the keys of cluster are members of a Class that has a property Features() as Integer. If so, the OP will need to cast v(0):

Dim v() As variant = cluster.Keys
Dim numDimensions as Integer = TheClass(v(0)).Features.Ubound + 1
1 Like