Re-declaring arrays of structures

mjcoon

Well-Known Member
Licensed User
The B4PPC help says that arays can be re-declared anywhere in a program (to change the size). I have done this many times with simple arrays but now I try it with an array of structures I get a syntax error message (running under desktop IDE, so far).

With no caveat about this in the help, it must be a bug?

Mike.
 

mjcoon

Well-Known Member
Licensed User
Can you post the code that you are trying to run?

Thanks Erel.

Perhaps first you would download StellaFerox's Planetarium and try running it under the IDE and then tell me why it fails on the call frmMain.Polygon().

Then insert
B4X:
Dim Type(X,Y) ArrayXY(0)
in the Sub Globals and
B4X:
Dim Type(X,Y) ArrayXY(Orbit + 1)
just before the line
B4X:
For JJ = J To J+Orbit Step Size

Of course if you can explain to me why my code is faulty without running it, that would be good too!

I have actually got it to work by using a 2D array instead of an array of structures, which is less readable although very similar (identical?) in operation though not in syntax. The complete modification of course requires two extra lines to set up the array content and a change of format of the frmMain.Polygon().

Regards, Mike.
 

agraham

Expert
Licensed User
Longtime User
I'm guessing but I am playing with the source of Basic4ppc and there is a bug in Polygon in the IDE in v6.90 that means that it doesn't accept Double arrays, Erel didn't quite finish converting it to accept Double as well as String arrays :(.
 
Last edited:

mjcoon

Well-Known Member
Licensed User
I'm guessing but I am playing with the source of Basic4ppc and there is a bug in Polygon in the IDE in v6.90 that means that it doesn't accept Double arrays, Erel didn't quite finish converting it to accept Double as well as String arrays :(.

Hi Andrew, thanks for looking. But on the face of it that doesn't explain how I got it to work using a 2D array rather than array of structures.

BTW I shall check with StellaFerox that it is OK to publish a slightly impproved, and still working, version of his source plus executable. Within his original thread to make the provenance clear.

Cheers (Happy New Year) Mike.
 

agraham

Expert
Licensed User
Longtime User
I had to go out but now I am back I have downloaded StellaFerox's Planetarium and don't get any error on the call to Polygon as he is using ArrayLists not arrays. What error do you get?

To redeclare your type you need to do

Dim ArrayXY(Orbit + 1, 2)

The "2" is the number of elements of the Type.
 

mjcoon

Well-Known Member
Licensed User
I had to go out but now I am back I have downloaded StellaFerox's Planetarium and don't get any error on the call to Polygon as he is using ArrayLists not arrays. What error do you get?

To redeclare your type you need to do

Dim ArrayXY(Orbit + 1, 2)

The "2" is the number of elements of the Type.

Thanks Andrew, but I thought that I had tried that variation, despite the fact that it conflicts with my original Global declaration of ArrayXY as a structure. If that is how it must be done then there should have been a warning in the Help!

On the matter of the ArrayList, I reported my problem, including error screen-shot, in an earlier thread which perhaps no-one read: http://www.b4x.com/forum/share-your-creations/5320-moons-jupiter-2.html#post75179.

I don't understand what the problem is; I'm using the beta version of 6.90. Maybe I should try an older version since I thought I had used ArrayLists myself in a similar context (but maybe not with Polygon).

Mike.
 

agraham

Expert
Licensed User
Longtime User
despite the fact that it conflicts with my original Global declaration of ArrayXY as a structure
Types are translated into arrays so there is no conflict.

I don't understand what the problem is; I'm using the beta version of 6.90
If it's a beta and not the final release its probably a bug that was fixed later, though as I said there is still a bug in Polygon in the final v6.90 release. Polygon was extensively altered to accept Number arrays as well as String arrays and arrayLists.
 
Top