How to declare a Multi-dimensional Array Property with Constants

I declared this as part of a window but I’m getting this error:

CardReview.StyRuns(kCSorce,) Declaration
Syntax error
StyRuns(kCSorce,) As StyleRun

kCSorce is a constant.

Apparently I cannot define a multi-dimensional array as a property WITH a constant.
It’s been a while since I’ve used this, since I now use classes.
I also cannot just declare an array
CardReview.StyRuns(,) As StyleRun

I know I did this before and also used constants in the property declaration

Is this now correct?

Maybe just an inconsistency, try to force it with StyRuns(kCSorce,-1) instead of StyRuns(kCSorce, )

Thanks. That works with a constant.
So we now have to use a number in each field.

I would really like to now how to confirm this is a standard or not.
I don’t like filing bug-reports.

If it doesn’t bother you enough to care, don’t fill it.

From Arrays docs it’s the standard way to declare a multidimensional array.
The size can be omitted only for one dimensional array.

From 2011 Language Reference

Dim arrayName(size [,size2,…sizeN]) as dataType

It is the same terminology, and in 2011, I could have just used commas. It just now it requires any number.

Not sure what you mean by “standard” in this context, but it is documented as being the proper syntax for Xojo.

In addition to @Maruizio’s Arrays link, also consider the Dim page syntax for arrays:

Dim arrayName ( size [, size2 ,… sizeN ]) As dataType

Note how the , for another dimension is followed by another sizeN which itself is not in a [ … ] block. Thus the sizeN is not itself optional. If you add a , for another dimension, you must also supply a size value. The size value itself is described as:

You pass as many size parameters as dimensions in the array. The size parameters must be numbers or constants.

So if you don’t know the size value to use as compile time, supply -1 either in the code itself or as a constant which is set to -1 if you consider that more readable.

Maybe this was true in 2011 but the 2020 docs differ

Doug. I am not disputing what you are stating. What I am stating is XOJO is becoming consistent. For many years, I didn’t need to include a number in a declaration.

I could write
Dim anarray( , , , ) As string and it would work.

BTW. How do I quote a previous statement in a conversation?
It’s not in the FAQ

Did you mean beocming inconsistent? Becoming consistent sounds to me like a good thing. And personally I do not mind having to specify -1 (or a constant) to make it clear another dimension was intentional.

What I do is simply highlight text in the original message, then you get a floating button that appears which says "Quote

Simply click that and it will start a new reply with the text quoted. Or if already in a reply, you can add another quote by repeating the process and highlighting more text in the original thread.

I agree. I am finally learning how to use StyleRuns. When it explained what a StyleRun was, it states

A StyleRun is a series of consecutive characters that have the same style attributes, as indicated by the StyleRun’ s properties.

Here I am trying to find out alternate ways of doing things, I realize from this definition I could have two ways of thinking about that.

  1. “Series of consecutive” means every character is included.
  2. It doesn’t and a StyleRun can be overlapping.

I asked in the forum and learned #2 isn’t possible. It’s okay. they can’t cover everything.

The current behavior seems

Dim arrayName( [size [, size2 ,… sizeN ]]) As dataType

As it allows the default -1 just the first level of omission as:

Dim arrayName( ) As dataType     // Same as arrayName( -1)

I think your memory is playing tricks on you. In a Dim statement, you have always needed to specify a value or -1. Now when you specify an array as a parameter of a method, then you can omit the size.

Sub MyMethod(someArray(,) as integer)

First level omission is allowed:

Dim a( ) As Object

Second level not:

Dim a( 2, ) As Object // Syntax error

Fixing it with explicit “second dimension is Empty” parameter:

Dim a( 2, -1 ) As Object
1 Like