[Gambas-user] Create an array inside a class

Benoit Minisini gambas at ...1...
Sun May 23 20:41:36 CEST 2004


On Sunday 23 May 2004 20:36, Grahame White wrote:
> Probably another silly question on my part but here goes :)
>
> I'm trying to create a class that has an array of shorts in it, something
> like this :
>
> list.class
>
> 	public name as string
> 	public row as short[]
>
> I then declare a public version :
>
> global.class
>
> 	static public mylist as list
>
> So far all this seems to work. I've been trying to add 10 lines to row like
> this :
>
> fmain.class
>
> public sub form_open()
>
> 	dim i as byte
>
> 	for i = 1 to 10
> 		global.mylist.row.add(0)
> 	next
>
> end
>
>
> And this is where I'm getting problems. When I try running this short
> snippet of code all I get is a 'Null Object' error. So what is the correct
> way to do this? I've looked in the docs they sort of skim over the subject
> of arrays and the examples don't cover this much either.
>
> Grahame
>

You must instanciate your array first. This way, for example,

list.class

 	public name as string
 	public row as NEW short[]


Regards,

-- 
Benoit Minisini
mailto:gambas at ...1...




More information about the User mailing list