[Gambas-user] Array decalarion

Benoît Minisini gambas at ...1...
Mon Sep 7 17:04:27 CEST 2009


> Benoît Minisini wrote:
> >> Hi,
> >>
> >> Why is method 1 of defining an array not allowed?
> >> Method 2 is the only one working, but looks clumsy when you have a lot
> >> of bytes.
> >>
> >> 1)
> >> DIM b AS Byte[] = [&HF0,  &H30,  &HF0, &H30]
> >>
> >> The error is "Type mismatch: wanted Byte[], got Integer[] instead"
> >
> > &HF0 is not a Byte, it is an Integer. You must do:
> >
> > DIM b AS Byte[] = [CByte(&HF0),  &H30,  &HF0, &H30]
> >
> > The type of the array created by the [ ... ] function is the type of the
> > first element.
> 
> That syntax gives the following....
> Type mismatch: wanted Byte[], got Variant[]
> 
> Only this seems to work...
> DIM b AS Byte[] = [CByte(&HF0), CByte(&H30), CByte(&HF0), CByte(&H30)]
> 
> But that even more code, than method 2.
> 
> [OperatingSystem]
> OperatingSystem=Linux
> KernelRelease=2.6.28-15-generic
> CPUArchitecture=x86_64
> DistributionVendor=ubuntu
> DistributionRelease="Ubuntu 9.04"
> 
> [Gambas]
> Gambas1=Not Installed
> Gambas2=2.16.0
> Gambas2Path=/usr/local/bin/gbx2
> Gambas3=Not Installed
> 
> 
> Regards,
> Ron_2nd.
> 

Sorry, the type of the array is given by the two first elements. If they are 
different, a Variant[] is returned.

Regards,

-- 
Benoît




More information about the User mailing list