Menu
JAQForum Ver 19.10.27

Forum Index : Microcontroller and PC projects : PicoMite BASIC STRUCTs

Posted: 11:02pm
17 Mar 2026
Copy link to clipboard
Mark
Regular Member

I have been programming in PicoMite BASIC 6.02 and really enjoy it. I've been experimenting with the new STRUCT's and find them powerful.  I find that arrays of STRUCTs inside a STRUCT don't behave as I am expecting;


TYPE KeyLink
 Link AS INTEGER
 Key AS STRING LENGTH 15
END TYPE

TYPE Tree
 TreeD AS INTEGER
 KeyLinks(20) AS KeyLink
END TYPE

DIM T as Tree, KL AS KeyLink
DIM L as INTEGER, K as STRING


This works, but there are couple things that don't work the way I expect based on my experience with other languages.  When declaring an array outside of a STRUCT, you can define a CONST and use that to define the array size, but inside a STRUCT (KeyLInks), it seems like. you have to use a number.

It seems like you can't use a subscript to access a KeyLinks member:


KL = T.KeyLinks(10)


This always seems to assign the value off T.KeyLinks(0) regardless of the subscript, but code like


L = T.KeyLInks(10).Link
K = T.KeyLinks(10).Key


Seems to work as expected.
 
Posted: 03:23am
18 Mar 2026
Copy link to clipboard
toml_12953
Guru

  Mark said  I have been programming in PicoMite BASIC 6.02 and really enjoy it. I've been experimenting with the new STRUCT's and find them powerful.  I find that arrays of STRUCTs inside a STRUCT don't behave as I am expecting;


TYPE KeyLink
 Link AS INTEGER
 Key AS STRING LENGTH 15
END TYPE

TYPE Tree
 TreeD AS INTEGER
 KeyLinks(20) AS KeyLink
END TYPE

DIM T as Tree, KL AS KeyLink
DIM L as INTEGER, K as STRING


This works, but there are couple things that don't work the way I expect based on my experience with other languages.  When declaring an array outside of a STRUCT, you can define a CONST and use that to define the array size, but inside a STRUCT (KeyLInks), it seems like. you have to use a number.

It seems like you can't use a subscript to access a KeyLinks member:


KL = T.KeyLinks(10)


This always seems to assign the value off T.KeyLinks(0) regardless of the subscript, but code like


L = T.KeyLInks(10).Link
K = T.KeyLinks(10).Key


Seems to work as expected.


I wouldn't expect T.KeyLinks(10) to work. Each KeyLinks element is made up of a Link and a Key. You have to specify which one you want when referencing KeyLinks
 
Posted: 04:03am
18 Mar 2026
Copy link to clipboard
Mark
Regular Member

Thanks for responding.

What I want to do is copy both the Key and Link parts of the KeyLink STRUCT at element 10 of the KeyLinks() array to the Key and Link parts of a scalar (non array) KeyLink variable. Why don't you expect it to work? (It doesn't).

Mark
 
Posted: 09:21am
18 Mar 2026
Copy link to clipboard
bfwolf
Senior Member

  Mark said  I have been programming in PicoMite BASIC 6.02 and really enjoy it. I've been experimenting with the new STRUCT's and find them powerful.  I find that arrays of STRUCTs inside a STRUCT don't behave as I am expecting;


TYPE KeyLink
 Link AS INTEGER
 Key AS STRING LENGTH 15
END TYPE

TYPE Tree
 TreeD AS INTEGER
 KeyLinks(20) AS KeyLink
END TYPE

DIM T as Tree, KL AS KeyLink
DIM L as INTEGER, K as STRING


This works, but there are couple things that don't work the way I expect based on my experience with other languages.  When declaring an array outside of a STRUCT, you can define a CONST and use that to define the array size, but inside a STRUCT (KeyLInks), it seems like. you have to use a number.


Sometime during the development phase of "Structs" in MMBasic, I also had some idea, but Peter said it was impossible because the UDTs (Type .. End Type) are created in a "pre-scan phase" even before the program is finally started. Constants defined with 'CONST' are treated essentially the same way as variables, meaning they receive their value at runtime. They just can't be changed later with [LET] constName=<expression>. Therefore, it makes sense that arrays within 'Type .. End Type' must have a literal as their MaxIndex. As I see it, MS-VBA handles it the same way:

https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/type-statement

Surprisingly (I didn't know this), MS then switched from 'Type .. End Type' to 'Structure .. End Structure' in VB.NET, possibly to get closer to C/C++. No need to understand it — MS logic...

https://learn.microsoft.com/en-us/dotnet/visual-basic/language-reference/data-types/user-defined-data-type
https://learn.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/structure-statement

  Mark said  It seems like you can't use a subscript to access a KeyLinks member:


KL = T.KeyLinks(10)


This always seems to assign the value off T.KeyLinks(0) regardless of the subscript, but code like


L = T.KeyLInks(10).Link
K = T.KeyLinks(10).Key


Seems to work as expected.


@Peter: This seems to be a bug - would also expect

KL = T.KeyLinks(10)

to work..

Regards, bfwolf
Edited 2026-03-18 19:22 by bfwolf
 
Posted: 11:27am
18 Mar 2026
Copy link to clipboard
Mark
Regular Member

More playing with STRUCTs.

This is just information, STRUCTs are working fine. I appreciate all the work that has gone into PicoMite BASIC. I'm treating my PicoMite as a retro computer and having a blast programming as I did (or should have) in the 1980's.

Outside of STRUCTs, BASIC doesn't like array with 1 element.


OPTION BASE 0

DIM I%(0)


and


OPTION BASE 1

DIM I%(1)


Both cause


Error: Dimensions


But


OPTION BASE 0

TYPE Test
  I(0) AS INTEGER
END TYPE


Is fine.

However, it appears that MMBASIC treats this as if the I array has two elements.


OPTION BASE 0

...

Test.I(0) = 0
Test.I(1) = 1

PRINT Test.I(0), Test.I(1)


Prints 0 and 1 as expected.


STRUCT(SIZEOF "Test")


Reports the same size (16) regardless of whether you use I(0) or I(1). If I add an additional element to the STRUCT


TYPE Test
 I(0) AS INTEGER
 J AS INTEGER
END TYPE



STRUCT(OFFSET "Test", "J")


Reports 16, regardless of I(0) or I(1).

Note, I noticed this behavior with a more complex STRUCT and simplified it for this post. These examples aren't intended to be useful code.

Thanks
Edited 2026-03-18 21:32 by Mark
 
Posted: 12:57pm
18 Mar 2026
Copy link to clipboard
matherp
Guru

Both will be fixed in next RC
 
Posted: 01:15pm
20 Mar 2026
Copy link to clipboard
Mark
Regular Member

Thanks for the information.
 


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2026