PC Review


Reply
Thread Tools Rate Thread

Class property as a Byte array

 
 
=?Utf-8?B?c2ltb25j?=
Guest
Posts: n/a
 
      20th Oct 2004
Can you define a property as type Byte array of a specific length?

I am trying to pass a byte array which is 3200 bytes in length from one form
(in which the bytes are read from a file) to another form (where the content
can be edited). I have defined a property for the editing form using the
following

Dim m_edicin(3199) As Byte
Public Property ebcdicin() As Byte
Get
edicin = m_ebcdicin
End Get
Set(ByVal Value As Byte)
m_edicin = Value
End Set
End Property

but it gives errors in the fourth and seventh lines of the type "Value of
type '1-dimensional array of Byte' cannot be converted to 'Byte'" or vice
versa.

What is the secret to make this work?

Grateful for any help.
 
Reply With Quote
 
 
 
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      21st Oct 2004
"simonc" <(E-Mail Removed)> schrieb:
> Can you define a property as type Byte array of a specific length?
>
> I am trying to pass a byte array which is 3200 bytes in length from one
> form
> (in which the bytes are read from a file) to another form (where the
> content
> can be edited). I have defined a property for the editing form using the
> following
>
> Dim m_edicin(3199) As Byte
> Public Property ebcdicin() As Byte
> Get
> edicin = m_ebcdicin
> End Get
> Set(ByVal Value As Byte)
> m_edicin = Value
> End Set
> End Property


\\\
Private m_EbdicIn() As Byte

Public Property EbdicIn() As Byte()
Get
Return m_EbdicIn
End Get
Set(ByVal Value() As Byte)
If Value.Length <> 3200 Then
Throw New ArgumentException(...)
Else
m_EbdicIn = Value
End If
End Set
End Property
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

 
Reply With Quote
 
Jay B. Harlow [MVP - Outlook]
Guest
Posts: n/a
 
      21st Oct 2004
Simonc,
You need to define the type of your property as Byte() which is byte array.

Something like:
> Public Property ebcdicin() As Byte()
> Get
> edicin = m_ebcdicin
> End Get
> Set(ByVal value As Byte())
> m_edicin = value
> End Set
> End Property


Note you cannot give the actual size of the array on the property itself,
you can however check the size of the array in the property.

Also remember Arrays are references so you are actually sharing the array in
this implementation. Consider using Array.Clone to prevent sharing a single
instance of the array. (especially in the Set).

Hope this helps
Jay

"simonc" <(E-Mail Removed)> wrote in message
news:A8B6051A-ED3F-46B7-A9B7-(E-Mail Removed)...
> Can you define a property as type Byte array of a specific length?
>
> I am trying to pass a byte array which is 3200 bytes in length from one
> form
> (in which the bytes are read from a file) to another form (where the
> content
> can be edited). I have defined a property for the editing form using the
> following
>
> Dim m_edicin(3199) As Byte
> Public Property ebcdicin() As Byte
> Get
> edicin = m_ebcdicin
> End Get
> Set(ByVal Value As Byte)
> m_edicin = Value
> End Set
> End Property
>
> but it gives errors in the fourth and seventh lines of the type "Value of
> type '1-dimensional array of Byte' cannot be converted to 'Byte'" or vice
> versa.
>
> What is the secret to make this work?
>
> Grateful for any help.



 
Reply With Quote
 
=?Utf-8?B?c2ltb25j?=
Guest
Posts: n/a
 
      21st Oct 2004
Thanks for explaining how to do this. It's a wonderful feeling when all those
wiggly blue lines under certain words disappear.

"Jay B. Harlow [MVP - Outlook]" wrote:

> Simonc,
> You need to define the type of your property as Byte() which is byte array.
>
> Something like:
> > Public Property ebcdicin() As Byte()
> > Get
> > edicin = m_ebcdicin
> > End Get
> > Set(ByVal value As Byte())
> > m_edicin = value
> > End Set
> > End Property

>
> Note you cannot give the actual size of the array on the property itself,
> you can however check the size of the array in the property.
>
> Also remember Arrays are references so you are actually sharing the array in
> this implementation. Consider using Array.Clone to prevent sharing a single
> instance of the array. (especially in the Set).
>
> Hope this helps
> Jay
>
> "simonc" <(E-Mail Removed)> wrote in message
> news:A8B6051A-ED3F-46B7-A9B7-(E-Mail Removed)...
> > Can you define a property as type Byte array of a specific length?
> >
> > I am trying to pass a byte array which is 3200 bytes in length from one
> > form
> > (in which the bytes are read from a file) to another form (where the
> > content
> > can be edited). I have defined a property for the editing form using the
> > following
> >
> > Dim m_edicin(3199) As Byte
> > Public Property ebcdicin() As Byte
> > Get
> > edicin = m_ebcdicin
> > End Get
> > Set(ByVal Value As Byte)
> > m_edicin = Value
> > End Set
> > End Property
> >
> > but it gives errors in the fourth and seventh lines of the type "Value of
> > type '1-dimensional array of Byte' cannot be converted to 'Byte'" or vice
> > versa.
> >
> > What is the secret to make this work?
> >
> > Grateful for any help.

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to convert a class/struct to a byte array? chrisben Microsoft C# .NET 0 7th Oct 2008 07:30 PM
Serializing a class into a byte array? Ole Microsoft Dot NET Compact Framework 6 29th Sep 2008 08:53 AM
Structure/Class to Byte Array and Back again Scott Townsend Microsoft VB .NET 8 9th Jun 2008 01:13 AM
assign byte array to struct or class Christian Havel Microsoft C# .NET 2 10th Mar 2008 11:14 AM
byte array via a class property Saurabh Kumar Microsoft VB .NET 12 27th Nov 2004 03:46 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:21 AM.