Shortcut to initialize a UDT

Started by MrBcx, March 24, 2025, 11:36:36 AM

Previous topic - Next topic

MrBcx

The non-shortcut way to accomplish the same thing:

TYPE foo
    DIM AS INT x, y, z          ' DIM AS is needed to propagate the INT datatype to x, y, z
END TYPE

DIM AS foo MyFoo

MyFoo.x = 1
MyFoo.y = 2
MyFoo.z = 3


PRINT MyFoo.x
PRINT MyFoo.y
PRINT MyFoo.z

PAUSE

Quin

Cool, I like it. Thanks for sharing! :)

MrBcx

I read a short thread on the FreeBasic forum about ways to initialize a UDT in FreeBasic.

I didn't find a related example in BcxHelp, so I'm sharing the following BCX example.

TYPE foo
    DIM AS INT x, y, z          ' DIM AS is needed to propagate the INT datatype to x, y, z
END TYPE

DIM AS foo MyFoo = { 1, 2, 3 }  ' This is how to initialize the members of MyFoo

PRINT MyFoo.x
PRINT MyFoo.y
PRINT MyFoo.z

PAUSE