473,396 Members | 1,866 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Copying arrays of different bases

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
Jun 27 '08 #1
4 1006
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" <12*@dfgh.comschreef in bericht
news:R6******************************@posted.plusn et...
>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
Jun 27 '08 #2
Thank you Cor. That is very informative. My problem is solved!

-Jerry
"Cor Ligthert[MVP]" <no************@planet.nlwrote in message
news:9B**********************************@microsof t.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" <12*@dfgh.comschreef in bericht
news:R6******************************@posted.plusn et...
>>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

Jun 27 '08 #3
"Jerry Spence1" <12*@dfgh.comschrieb:
>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/>

Jun 27 '08 #4
>
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

Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Marijn | last post by:
Say i have an object that represents or holds a resource like an open file, a block of memory on the heap, or an openGL texture object. The constructor acquires the resource, and the destructor...
10
by: David Rasmussen | last post by:
If I have this struct S { int arr; }; and I do this: S s1,s2;
21
by: Matteo Settenvini | last post by:
Ok, I'm quite a newbie, so this question may appear silly. I'm using g++ 3.3.x. I had been taught that an array isn't a lot different from a pointer (in fact you can use the pointer arithmetics to...
5
by: Roy Hills | last post by:
When I'm reading from or writing to a network socket, I want to use a struct to represent the structured data, but must use an unsigned char buffer for the call to sendto() or recvfrom(). I have...
14
by: Erik Frey | last post by:
Hello, Say I have the following two classes: class Base { } class Inherited : Base {
1
by: Mark Smith | last post by:
I'm trying to copy data from a 1D array to a 2D array. The obvious thing doesn't work: int twoDee = new int; int oneDee = new int { 1, 2 }; Array.Copy(oneDee, 2, twoDee, 2, 2); This causes a...
2
by: Enrique Bustamante | last post by:
Casting arrays that works on watch and command window but not in code. My application is casting arrays in a way it should work. To test if I was doing something invalid, I wrote a test code that...
6
by: Vitaly Zayko | last post by:
It's probably simple but I can't find a way how to copy number of bytes from one byte array to another? Just like Array.Copy(SourceArray, SourceIndex, DestArray, DestIndex, Length) does but in my...
19
by: arnuld | last post by:
/* C++ Primer - 4/e * chapter 4- Arrays & Pointers, exercise 4.28 * STATEMENT * write a programme to read the standard input and build a vector of integers from values that are read....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.