Hi,

Anyone know an efficient way to convert a long array to a byte array. Of
course you can do this by masking and dividing by 256 four times for each
long element, but is there anything built into VB to accomplish this faster?

Dave

Re: Convert Long array to Byte array by Tony

Tony
Sat Sep 11 04:13:24 CDT 2004

Here's a worked example for you to play with Dave:


Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _
Destination As Any, Source As Any, ByVal Length As Long)

Private Sub Form_Load()
Dim l(0 To 3) As Long, b() As Byte, i As Integer, iSize As Integer

' Populate long array with some dummy values
l(0) = &H3020100: l(1) = &H7060504: l(2) = &HB0A0908: l(3) = &HF0E0D0C

' Make byte array of a compatible size
iSize = 4 * (UBound(l) - LBound(l) + 1)
ReDim b(0 To iSize - 1)

' Now transfer the contents of long array to byte array
CopyMemory b(0), l(0), iSize

' Now confirm the byte array contents
For i = LBound(b) To UBound(b)
Debug.Print "b(" & CStr(i) & ") = &H" & Hex(b(i))
Next i
End Sub


Tony Proctor

"Dave" <dave5398@btinternet.com> wrote in message
news:#0YulO1lEHA.1652@TK2MSFTNGP09.phx.gbl...
> Hi,
>
> Anyone know an efficient way to convert a long array to a byte array. Of
> course you can do this by masking and dividing by 256 four times for each
> long element, but is there anything built into VB to accomplish this
faster?
>
> Dave
>
>



Re: Convert Long array to Byte array by Steve

Steve
Sat Sep 11 13:19:17 CDT 2004

Private Type mtypFromLong
LongVal As Long
End Type

Private Type mtypToBytes
aBytes(0 To 3) As Byte
End Type

Public Function LongToByteA(LongVal As Long) As Byte()
Dim FromLong As mtypFromLong
Dim ToBytes As mtypToBytes

FromLong.LongVal = LongVal
LSet ToBytes = FromLong
LongToByteA = ToBytes.aBytes
End Function

On Fri, 10 Sep 2004 17:31:35 +0100, "Dave" <dave5398@btinternet.com> wrote:

>Hi,
>
>Anyone know an efficient way to convert a long array to a byte array. Of
>course you can do this by masking and dividing by 256 four times for each
>long element, but is there anything built into VB to accomplish this faster?
>
>Dave
>


Re: Convert Long array to Byte array by Dave

Dave
Sat Sep 11 15:10:29 CDT 2004

Thanks for the help, I did not know about these VB methods.

Dave

"Dave" <dave5398@btinternet.com> wrote in message
news:#0YulO1lEHA.1652@TK2MSFTNGP09.phx.gbl...
> Hi,
>
> Anyone know an efficient way to convert a long array to a byte array. Of
> course you can do this by masking and dividing by 256 four times for each
> long element, but is there anything built into VB to accomplish this
faster?
>
> Dave
>
>



Re: Convert Long array to Byte array by Michael

Michael
Sat Sep 11 15:16:51 CDT 2004

Dave wrote:
> Thanks for the help, I did not know about these VB methods.


Note that if you ever want/need to port this VB code to VB.Net that LSet and
RSet aren't supported in VB.Net.


>
> Dave
>
> "Dave" <dave5398@btinternet.com> wrote in message
> news:#0YulO1lEHA.1652@TK2MSFTNGP09.phx.gbl...
>> Hi,
>>
>> Anyone know an efficient way to convert a long array to a byte
>> array. Of course you can do this by masking and dividing by 256
>> four times for each long element, but is there anything built into
>> VB to accomplish this faster?
>>
>> Dave

--
Michael Harris
Microsoft.MVP.Scripting
Sammamish WA US


Re: Convert Long array to Byte array by Dave

Dave
Sat Sep 11 15:31:16 CDT 2004

But do you reckon they would be supported on a Chillisoft ASP server??

Dave

"Michael Harris (MVP)" <mikhar at mvps dot org> wrote in message
news:OD5rGxDmEHA.716@TK2MSFTNGP10.phx.gbl...
> Dave wrote:
> > Thanks for the help, I did not know about these VB methods.
>
>
> Note that if you ever want/need to port this VB code to VB.Net that LSet
and
> RSet aren't supported in VB.Net.
>
>
> >
> > Dave
> >
> > "Dave" <dave5398@btinternet.com> wrote in message
> > news:#0YulO1lEHA.1652@TK2MSFTNGP09.phx.gbl...
> >> Hi,
> >>
> >> Anyone know an efficient way to convert a long array to a byte
> >> array. Of course you can do this by masking and dividing by 256
> >> four times for each long element, but is there anything built into
> >> VB to accomplish this faster?
> >>
> >> Dave
>
> --
> Michael Harris
> Microsoft.MVP.Scripting
> Sammamish WA US
>



Re: Convert Long array to Byte array by Bob

Bob
Sat Sep 11 16:04:31 CDT 2004

Only if you are planning on running a compiled VB application or dll there.

There seems to be some confusion here: VB does not equal vbscript.
http://msdn.microsoft.com/library/en-us/script56/html/vsgrpNonFeatures.asp

You asked for VB code so the helpful people gave you some VB code despite
its being offtopic. Now it appears that you really wanted vbscript code.
The code you've been given will not run under ASP, unless you compile it
into an activeX dll.

Bob Barrows

Dave wrote:
> But do you reckon they would be supported on a Chillisoft ASP server??
>
> Dave
>
> "Michael Harris (MVP)" <mikhar at mvps dot org> wrote in message
> news:OD5rGxDmEHA.716@TK2MSFTNGP10.phx.gbl...
>> Dave wrote:
>>> Thanks for the help, I did not know about these VB methods.
>>
>>
>> Note that if you ever want/need to port this VB code to VB.Net that
>> LSet and RSet aren't supported in VB.Net.
>>
>>
>>>
>>> Dave
>>>
>>> "Dave" <dave5398@btinternet.com> wrote in message
>>> news:#0YulO1lEHA.1652@TK2MSFTNGP09.phx.gbl...
>>>> Hi,
>>>>
>>>> Anyone know an efficient way to convert a long array to a byte
>>>> array. Of course you can do this by masking and dividing by 256
>>>> four times for each long element, but is there anything built into
>>>> VB to accomplish this faster?
>>>>
>>>> Dave
>>
>> --
>> Michael Harris
>> Microsoft.MVP.Scripting
>> Sammamish WA US

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"



Re: Convert Long array to Byte array by Dave

Dave
Sun Sep 12 05:40:30 CDT 2004

Thanks. The page you cite has been very helpful.

However, I asked for both cases as I am progamming an application in VB
itself, running at the client end which asks for services at the server end.
In this case I do need this feature at both ends. As it turns out, I now
need to use my cruder dividing by 256 routine at the server end as I am a
beginner at ASP and had forgotten you can only use variants there.

Dave

"Bob Barrows [MVP]" <reb01501@NOyahoo.SPAMcom> wrote in message
news:#Cl1wLEmEHA.2820@TK2MSFTNGP15.phx.gbl...
> Only if you are planning on running a compiled VB application or dll
there.
>
> There seems to be some confusion here: VB does not equal vbscript.
> http://msdn.microsoft.com/library/en-us/script56/html/vsgrpNonFeatures.asp
>
> You asked for VB code so the helpful people gave you some VB code despite
> its being offtopic. Now it appears that you really wanted vbscript code.
> The code you've been given will not run under ASP, unless you compile it
> into an activeX dll.
>
> Bob Barrows
>
> Dave wrote:
> > But do you reckon they would be supported on a Chillisoft ASP server??
> >
> > Dave
> >
> > "Michael Harris (MVP)" <mikhar at mvps dot org> wrote in message
> > news:OD5rGxDmEHA.716@TK2MSFTNGP10.phx.gbl...
> >> Dave wrote:
> >>> Thanks for the help, I did not know about these VB methods.
> >>
> >>
> >> Note that if you ever want/need to port this VB code to VB.Net that
> >> LSet and RSet aren't supported in VB.Net.
> >>
> >>
> >>>
> >>> Dave
> >>>
> >>> "Dave" <dave5398@btinternet.com> wrote in message
> >>> news:#0YulO1lEHA.1652@TK2MSFTNGP09.phx.gbl...
> >>>> Hi,
> >>>>
> >>>> Anyone know an efficient way to convert a long array to a byte
> >>>> array. Of course you can do this by masking and dividing by 256
> >>>> four times for each long element, but is there anything built into
> >>>> VB to accomplish this faster?
> >>>>
> >>>> Dave
> >>
> >> --
> >> Michael Harris
> >> Microsoft.MVP.Scripting
> >> Sammamish WA US
>
> --
> Microsoft MVP - ASP/ASP.NET
> Please reply to the newsgroup. This email account is my spam trap so I
> don't check it very often. If you must reply off-line, then remove the
> "NO SPAM"
>
>