[Gambas-user] Null Object

Laurent Carlier lordheavy at ...512...
Sat Jul 9 13:34:45 CEST 2005


Maurizio Pozzobon a écrit :
> hi list
> I'm writing a little program in gambas 1.0.6, but I've have a problem, the 
> sub I'm writing need to check the value of an integer array (TotI) and based 
> on the value of TotI add the corresponding object of another array in a 
> third array of objects, I know it seams crazy! here is the code I've 
> written:
> 
> SUB check() ' find the better line to draw
> DIM i AS Integer
> DIM j AS Integer
> DIM ZeroClick AS Object[] 'square with all borders unclicked
> DIM Zc AS Integer 'Counter for zeroclick
> DIM OneClick AS Object[] 'square with 1 border clicked
> DIM Oc AS Integer 'Counter for Oneclick
> DIM TwoClick AS Object[] 'square with 2 borders clicked
> DIM Twc AS Integer 'Counter for Twoclick
> DIM ThreeClick AS Object[] 'square with 3 borders clicked
> DIM Thc AS Integer 'Counter for Threeclick
> FOR i = 0 TO nbx - 1
> FOR j = 0 TO nby - 1
> IF TotI[i,j]=0 THEN 
> zeroclick.Add(Tot[i,j],Zc)
> Zc =Zc + 1 
> ELSE
> IF TotI[i,j]=1 THEN 
> Oneclick.Add(Tot[i,j],Oc)
> Oc =Oc + 1 
> ELSE
> IF TotI[i,j]=2 THEN 
> Twoclick.Add(Tot[i,j],Twc)
> Twc =Twc + 1 
> ELSE
> IF TotI[i,j]=3 THEN 
> Threeclick.Add(Tot[i,j],Thc)
> Thc =Thc + 1 
> END IF
> END IF
> END IF
> END IF
> NEXT
> NEXT
> END
> 
> My problem is that when gambas reach the "zeroclick.Add(Tot[i,j],Zc)" 
> command give me an error, Null object, I can't understand what's the 
> problem, I even tried to simply resize the array zeroclick but gambas give 
> me the same error.
> 
> Thanks
> 

DIM ZeroClick AS Object[]
With this you define that ZeroClick will be an array of Object but you
don't create the array. You must instanciate it with the NEW keyword

Like this :
DIM ZeroClick AS NEW Object[]
or like this :
DIM ZeroClick AS Object[]
ZeroClick = NEW Object[]

This you be the same with all your Object[] array.

Regards,

-- 

Laurent Carlier
jabber : LordHeavy at ...943...




More information about the User mailing list