[Gambas-user] Creating a Variant[] on the fly

Bruce Bruen bbruen at ...2308...
Mon Apr 18 10:15:16 CEST 2011


On Monday, April 18, 2011 03:11:22 PM Bruce Bruen wrote:
> I have a custom gridview control which has a method "Add", which adds a
> Variant[] array into an internal collection. IOW it exposes the method :
> 
> PUBLIC SUB Add(dataitem as Variant[], key as String)
> 
> This allows me to add "any" type of data into the grideview row as the
> custom control knows how to convert the received data into strings.
> 
> But when I try the following:
> 	csvRelData.Add([.LocalCardinality, .TargetCardinality], "Cardinalities")
> where .LocalCardinality and .TargetCardinality are both integers, I get a
> "Type mismatch: wanted Variant[], got Integer[] instead" error.
> 
> I know I could declare and load a Variant[] variable locally, item by item,
> but this expands the code so much.
> 
> (The control is going to display something like the PropertyList in the IDE
> but there are three columns, the parameter name, eg "Cardinalities" and two
> values, one for the local instance and one for the target instance.)
> 
> Is there (again) something simple that I just can't see today to make this
> construct work?

Nevermind, I got around it by 

DIM vArray as New Variant[]

	varray=["Cardinalities",.LocalCardinality,.TargetCardinality]
	csvRelData.Add(varray,"Cardinalities")
	varray=["Transpose",.LocalSliceMethod,.TargetSliceMethod]
	csvRelData.Add(varray,"Transpose"]
	etc

which only doubles the size of the code.  

But it would be nice if there was some way to cast an array as Variant[] :-)

-- 
best regards
Bruce Bruen




More information about the User mailing list