[Gambas-user] Class array
Alberto Torres
kungfoobar at ...626...
Sat Nov 26 21:11:39 CET 2005
The problems with objects is that must be declared
Dim myClassArray as Object[](10)
myClassArray[0] = NEW myClass
myClassArray[0].name="john smith"
myClassArray[1] = NEW myClass
myClassArray[1].phone=123456
If you don't specify the size of the array:
Dim myClassArray as Object[]
dim asdf as new myClass
myClassArray.Add(asdf)
If you want to allocate X elements in the array:
DIM i as Integuer
DIM my as myClass
FOR i=0 to X-1
my = NEW myClass
myClassArray.Add(my)
NEXT
Or better:
DIM i as Integuer
myClassArray.Resize(X)
FOR i=0 to X-1
myClassArray[i] = NEW myClass
NEXT
Check gb.Object[] in help
Hope it helps
Cheers
2005/11/26, tine melk <melk54 at ...67...>:
> Is there a way and if so how to use array in class.
> this "dim myclass as new class1[]" looks like are allowed but
> how to access it?
>
> Running Gambas 1.9.21 on ubuntu 5.10
>
> class1.class
>
> public name as string
> public phone as string
>
> main.gb
>
> dim myclass as new class1[]
>
> public sub main()
>
> 'Should'nt it be possible to
> myclass[1].name="dummy"
> myclass[2].phone="0123456"
>
> end sub
>
--
DiThi
e-mail: kungfoobar at ...626...
Jabber ID: dithi at ...646...
More information about the User
mailing list