[Gambas-user] Can someone explain why this works?

Benoît Minisini gambas at ...1...
Thu May 5 19:24:36 CEST 2011


> > Benoit,
> > 
> > Can you explain why this works and the reasoning behind it?
> > I would think there would be dimension issues on some lines
> > 
> > 
> > DIM i AS Integer, Text AS String[4, 4, 4, 4]
> > 
> > Text = ["Just", "test"]        '<--how to load Text with multi-dimension
> > text
> > 
> > FOR i = 0 TO Text.Max
> > 
> >     PRINT Text[i]              '<--why does this not show bad dimensions
> > 
> > error? NEXT
> > 
> > 
> > -Fernando
> 
> Mmm, it shouldn't. It should raise an error instead. It's a bug.

No, it's not a bug, it's perfectly legal. (Sorry, I'm a bit tired, I've just 
came back from my monthly theatre stage).

A String array of four dimensions or of one dimension have the same class: 
"String[]".

By using the [...] operator, you are creating a new one-dimensional array. 
That can you can legally assign to Text, which waits for a String[]. Then you 
lose your four-dimensional array after the assignment.

Regards,

-- 
Benoît Minisini




More information about the User mailing list