I have one array which is base 1 (rather than 0) and I am trying to use
array.copy to copy it into a new array. I get the error:

Unable to cast object of type 'System.Byte[*]' to type 'System.Byte[]'.

I think this is because the new array, by default is base 0. Without
creating a wasteful loop and handling byte for byte, how can I create a base
0 array from a base 1 array?

-Jerry

Re: Copying arrays of different bases by Cor

Cor
Fri May 09 02:42:39 CDT 2008

Jerry,

All arrays are Base 0 arrays, with the conversion from VB6 to VB 2002 they
have made the in my opinion wrong simple decission to add 1 element after
every array in VB rather then let the microsoft.VisualBasic functins start
on 0 (while logical using the first as 1). The VB6 lobby was very strong in
those days, in fact the wanted absolute no changes in VB6.

We have to deal with that now.

To give you a sample how you can copy. However if you have non fixed arrays
it is better to avoid them there are more alternatives for that, than I can
write here.

\\\\
Dim A() As Byte = {1}
Dim B(A.Length - 1) As Byte
A.Copy(A, B, A.Length)
///

Cor

"Jerry Spence1" <123@dfgh.com> schreef in bericht
news:R6adncVA8L23Ib7VnZ2dnUVZ8vydnZ2d@posted.plusnet...
>I have one array which is base 1 (rather than 0) and I am trying to use
>array.copy to copy it into a new array. I get the error:
>
> Unable to cast object of type 'System.Byte[*]' to type 'System.Byte[]'.
>
> I think this is because the new array, by default is base 0. Without
> creating a wasteful loop and handling byte for byte, how can I create a
> base 0 array from a base 1 array?
>
> -Jerry
>


Re: Copying arrays of different bases by Jerry

Jerry
Sat May 10 03:35:12 CDT 2008

Thank you Cor. That is very informative. My problem is solved!

-Jerry


"Cor Ligthert[MVP]" <notmyfirstname@planet.nl> wrote in message
news:9BFF848D-2D31-47DB-94B5-A6536EEB0BFE@microsoft.com...
> Jerry,
>
> All arrays are Base 0 arrays, with the conversion from VB6 to VB 2002 they
> have made the in my opinion wrong simple decission to add 1 element after
> every array in VB rather then let the microsoft.VisualBasic functins start
> on 0 (while logical using the first as 1). The VB6 lobby was very strong
> in those days, in fact the wanted absolute no changes in VB6.
>
> We have to deal with that now.
>
> To give you a sample how you can copy. However if you have non fixed
> arrays it is better to avoid them there are more alternatives for that,
> than I can write here.
>
> \\\\
> Dim A() As Byte = {1}
> Dim B(A.Length - 1) As Byte
> A.Copy(A, B, A.Length)
> ///
>
> Cor
>
> "Jerry Spence1" <123@dfgh.com> schreef in bericht
> news:R6adncVA8L23Ib7VnZ2dnUVZ8vydnZ2d@posted.plusnet...
>>I have one array which is base 1 (rather than 0) and I am trying to use
>>array.copy to copy it into a new array. I get the error:
>>
>> Unable to cast object of type 'System.Byte[*]' to type 'System.Byte[]'.
>>
>> I think this is because the new array, by default is base 0. Without
>> creating a wasteful loop and handling byte for byte, how can I create a
>> base 0 array from a base 1 array?
>>
>> -Jerry
>>
>



Re: Copying arrays of different bases by Herfried

Herfried
Sat May 10 12:25:33 CDT 2008

"Jerry Spence1" <123@dfgh.com> schrieb:
>I have one array which is base 1 (rather than 0) and I am trying to use
>array.copy to copy it into a new array. I get the error:
>
> Unable to cast object of type 'System.Byte[*]' to type 'System.Byte[]'.
>
> I think this is because the new array, by default is base 0. Without
> creating a wasteful loop and handling byte for byte, how can I create a
> base 0 array from a base 1 array?

Take a look at 'Buffer.BlockCopy' to efficiently copy one byte array to
another.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>


Re: Copying arrays of different bases by Cor

Cor
Sun May 11 01:37:56 CDT 2008

>
> Take a look at 'Buffer.BlockCopy' to efficiently copy one byte array to
> another.
>
True,

(But does not describe direct so easily the problem and therefore less
documentative, but for high use, for sure to take).

Cor