Exist a Type for more than one variable?

New to FreeBASIC? Post your questions here.
Post Reply
Luis Babboni
Posts: 375
Joined: Mar 15, 2015 12:41

Exist a Type for more than one variable?

Post by Luis Babboni »

I´m coming from the Sinclair Spectrum Basic and I use arrays for everything.

I discovered something interesting in clarity that is "Type".

Instead of Array (1 to 3) I could use:
Array.ThingA; Array.ThingB and Array.ThingC

What about if I need Array (1 to 2, 1 to 2)?
Exist something that allow me to use things like:
Array.ThingA.Piece1; Array.ThingA.Piece2; Array.ThingB.Piece1 and Array.ThingB.Piece2?

Thanks.
Luis Babboni
Posts: 375
Joined: Mar 15, 2015 12:41

Re: Exist a Type for more than one variable?

Post by Luis Babboni »

This is the best I could do.
Exists something better?

Code: Select all

Type ListaMovidas
	Desde As Integer
	Hacia As Integer
	Tipo As Integer
	Corona As Integer
	AlPaso As Integer
	ValorOrden As Integer	
End Type

Dim Shared LM(1 To 100,1 To 500) As ListaMovidas

Dim As Integer Profundidad, Movida

Profundidad=5
Movida=23

LM(Profundidad, Movida).Hacia=3

Print LM(Profundidad, Movida).Hacia

Sleep

SARG
Posts: 1764
Joined: May 27, 2005 7:15
Location: FRANCE

Re: Exist a Type for more than one variable?

Post by SARG »

Types can be nested.

Code: Select all

type typethingA
	piece1 as Integer
	piece2 as integer
end type
type typethingb
	piece1 as integer
	piece2 as integer
end type

type typearray
	thingA as typethingA
	thingB as typethingB
end type

dim as typearray array(5)

array(1).thingA.piece1=10
array(4).thingB.piece2=15

print array(1).thingA.piece1
print array(4).thingB.piece2

sleep
Luis Babboni
Posts: 375
Joined: Mar 15, 2015 12:41

Re: Exist a Type for more than one variable?

Post by Luis Babboni »

SARG wrote:Types can be nested.

Code: Select all

type typethingA
	piece1 as Integer
	piece2 as integer
end type
type typethingb
	piece1 as integer
	piece2 as integer
end type

type typearray
	thingA as typethingA
	thingB as typethingB
end type

dim as typearray array(5)

array(1).thingA.piece1=10
array(4).thingB.piece2=15

print array(1).thingA.piece1
print array(4).thingB.piece2

sleep
Nice! Thanks SARG! :-)
Post Reply