Maybe you are right that I should use MidB instead of Mid$.
On the other hand, AscB will only return the value of the first byte no
matter the long of a string, so it does not give me the result I want.
Daniel
-----Mensaje original-----
De: Chris Tacke [mailto:ctacke@r...]
Enviado el: Viernes, 29 de Junio de 2001 12:16 p.m.
Para: professional vb
Asunto: [pro_vb] RE: Reading strings as numbers
Instead of using Mid, which returns a string, use AscB and MidB, which
returns bytes.
So if you have a string S that actually contains &H12345678, you want to
pull &H12 and &H34 as Integers, but &H5678 as a Long
Dim i As Integer
Dim j As Integer
Dim k As Long
i = AscB(MidB(S, 1, 2))
j = AscB(MidB(S, 3, 2))
k = AscB(MidB(S, 5, 4))
----------------------------
Christopher Tacke, MCSD
President, Innovative Decision Support Systems
innovativedss.com
> -----Original Message-----
> From: danielweigel@y... [mailto:danielweigel@y...]
> Sent: Friday, June 29, 2001 1:01 AM
> To: professional vb
> Subject: [pro_vb] Reading strings as numbers
>
>
> I am looking for an efficient and fast way to 'read' the same bytes as
> diferent data types, much like C++ unions.
> In my case I would like to have a string that contains several numbers in
> his proper binary format. An integer occuping two bytes, a single four
> bytes, and so on.
>
> Supose that I have an string S and I know that the two bytes
> starting at the
> position n represents an integer, I would like a function that return me
> that integer:
> i = DesiredFunction(Mid$(S,n,2))
> and also I would need an inverse function:
> Mid$(S,n,2)=InverseFunction(i)
>
> Should I need to write a C++ dll or can I do it efficiently in VB?
>
> Thank you in advance,
>
> Daniel