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 4 1019
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.Visua lBasic 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.comsc hreef in bericht
news:R6******** *************** *******@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
Thank you Cor. That is very informative. My problem is solved!
-Jerry
"Cor Ligthert[MVP]" <no************ @planet.nlwrote in message
news:9B******** *************** ***********@mic rosoft.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.Visua lBasic 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.comsc hreef in bericht
news:R6******** *************** *******@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
"Jerry Spence1" <12*@dfgh.comsc hrieb:
>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.BlockCo py' 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/>
>
Take a look at 'Buffer.BlockCo py' 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 releases it. I
want to implement efficient copying and assignment for this object -
the copy constructor passes on the 'handle' (file pointer, memory
pointer, or opengl texture id) to the new object, and invalidates the
old object. I guess this is...
|
by: David Rasmussen |
last post by:
If I have this
struct S
{
int arr;
};
and I do this:
S s1,s2;
|
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 "browse" it). So I
expected that when I run this program, I get both c1.A and c2.A
pointing to the same address, and changing c1.A means that also c2.A
changes too.
----- BEGIN example CODE -----------
|
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 two questions:
1. Is it generally safe to "overlay" the structure on the buffer,
e.g.:
unsigned char buffer;
|
by: Erik Frey |
last post by:
Hello,
Say I have the following two classes:
class Base
{
}
class Inherited : Base
{
| |
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 RankException. But the MSDN documentation says:
When copying between multidimensional arrays, the array
|
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 has similar
structure of the classes in my application. The test worked fine, the
casting I want to do must work. I compared the structure of the test
with the application to ensure they where similar (inheriting twice,
base class implements...
|
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 case the
arrays have different length. Of course I can copy byte by byte but I
guess there should be a function for such task.
Thanks!
--
Vit Zayko
|
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. allocate an array of the same
size as the vector and copy elements from the vector into the array
*/
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |