Class property as a Byte array

G

Guest

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.
 
H

Herfried K. Wagner [MVP]

simonc said:
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
///
 
J

Jay B. Harlow [MVP - Outlook]

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
 
G

Guest

Thanks for explaining how to do this. It's a wonderful feeling when all those
wiggly blue lines under certain words disappear.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top