Code: Select all

#macro arrayinsert(a,index,insert)

If index>=Lbound(a) And index<=Ubound(a)+1 Then

Var index2=index-Lbound(a)

Redim Preserve a(Lbound(a) To Ubound(a)+1)

For x As long= Ubound(a) To Lbound(a)+index2+1 Step -1

Swap a(x),a(x-1)

Next x

a(Lbound(a)+index2)=insert

End If

#endmacro

#macro arraydelete(a,index)

If index>=Lbound(a) And index<=Ubound(a) Then

For x As long=index To Ubound(a)-1

a(x)=a(x+1)

Next x

Redim Preserve a(Lbound(a) To Ubound(a)-1)

End If

#endmacro

type monster

as long headsize

as long taillength

as long bodythickness

as string name

as long teethsize(1 to 20)

as single averagetoothsize

declare constructor

declare sub show

static index as long

end type

dim monster.index as long

constructor monster

index+=1

headsize=rnd*50

taillength=headsize+rnd*50

bodythickness=3*headsize

name="Monster "+str(index)

dim as single a

for n as long=1 to 20

teethsize(n)=rnd*headsize/10

a+=teethsize(n)

next n

averagetoothsize=a/20

end constructor

sub monster.show

print "Headsize","taillength","bodythickness","name","average tooth size"

print headsize,taillength,bodythickness,name,averagetoothsize

end sub

redim as monster m(1 to 3)

for n as long=1 to 3

m(n).show

next

print:print

dim as monster temp

monster.index-=1

arrayinsert(m,ubound(m)+1,temp)

print "push one at back"

for n as long=lbound(m) to ubound(m)

m(n).show

next

print:print

print "pop one at index 3"

arraydelete(m,3)

for n as long=lbound(m) to ubound(m)

m(n).show

next

print:print

temp.constructor

monster.index-=1

print "push new one at index 2"

arrayinsert(m,2,temp)

for n as long=lbound(m) to ubound(m)

m(n).show

next

print:print

sleep