Home All Groups Group Topic Archive Search About

Unsigned C long to signed VB5 Long query.

Author
22 Feb 2009 9:47 PM
Richard Brooks
I've been searching high and low for the right solution to what should
be something simple and instead of the what I have read as 'If you
pass an unsigned value greater than 2,147,483,647 to a LONG variable,
the value will be interperted as a negarive number.' instead I get the
'value overflow' result.

What is the correct method for getting an unsigned LONG value into a
VB Signed LONG?


Many thanks.

Author
23 Feb 2009 12:00 AM
Bill McCarthy
Hi Richard,

Long in VB is 32 bits, as is LONG in C.  If you are merely representing the
value use the bitwise value. How the high order bit is interpreted only
matter when you are converting the value out of the storage type or doing
manipulation on it.

For example, if the C value is 0x80000001 then the VB long value is
&H80000001  in terms of bits.

So typically you can ignore the fact the sign bit has special meaning,
unless you are converting values such as double to string to Long, or you
are trying to do maths on them etc.

Oh, and when using bitwise values, always use And, Or, XOr and Not; not
numeric operators.



Show quoteHide quote
"Richard Brooks" <richardbro***@vickers-armstrongs.com> wrote in message
news:3_udncnD-J9GWjzUnZ2dnUVZ8s_inZ2d@bt.com...
> I've been searching high and low for the right solution to what should be
> something simple and instead of the what I have read as 'If you pass an
> unsigned value greater than 2,147,483,647 to a LONG variable, the value
> will be interperted as a negarive number.' instead I get the 'value
> overflow' result.
>
> What is the correct method for getting an unsigned LONG value into a VB
> Signed LONG?
>
>
> Many thanks.
Author
23 Feb 2009 12:29 AM
Larry Serflaten
"Richard Brooks" <richardbro***@vickers-armstrongs.com> wrote
> I've been searching high and low for the right solution to what should
> be something simple and instead of the what I have read as 'If you
> pass an unsigned value greater than 2,147,483,647 to a LONG variable,
> the value will be interperted as a negarive number.' instead I get the
> 'value overflow' result.
>
> What is the correct method for getting an unsigned LONG value into a
> VB Signed LONG?

Well the trick there is, where are you getting the unsigned long?

You can assign any supported value you want using hexidecimal
notation:

Z = &HFFFFFFFF

LFS
Author
23 Feb 2009 3:45 AM
Richard Brooks
Larry Serflaten said the following on 23/02/2009 00:29:
Show quoteHide quote
> "Richard Brooks" <richardbro***@vickers-armstrongs.com> wrote
>> I've been searching high and low for the right solution to what should
>> be something simple and instead of the what I have read as 'If you
>> pass an unsigned value greater than 2,147,483,647 to a LONG variable,
>> the value will be interperted as a negarive number.' instead I get the
>> 'value overflow' result.
>>
>> What is the correct method for getting an unsigned LONG value into a
>> VB Signed LONG?
>
> Well the trick there is, where are you getting the unsigned long?
>
> You can assign any supported value you want using hexidecimal
> notation:
>
> Z = &HFFFFFFFF
>
> LFS

Thanks for the reply (and to Bill McCarthy in other post).

My task is to read in aircraft position data from a file built by a
flight data recorder, FS recorder programmed by Matthias Neusinger who
has kindly sent me the subroutines and data formats which is
programmed in C which IIRC writes in Low Byte Order First, so in a
four byte data block, the right-hand most byte block is the High Byte
value.

I think the problem is now sorted as I was converting and multiplying
each byte then adding that subtotal value to a Long variable but now,
just building the byte block and converting it at the end works.

A very many thanks to you both.
Author
23 Feb 2009 9:55 AM
Bill McCarthy
Hi Richard,

Show quoteHide quote
"Richard Brooks" <richardbro***@vickers-armstrongs.com> wrote in message
news:_c-dndGfKc9whj_UnZ2dnUVZ8h2dnZ2d@bt.com...
> Larry Serflaten said the following on 23/02/2009 00:29:
>> "Richard Brooks" <richardbro***@vickers-armstrongs.com> wrote
>>> I've been searching high and low for the right solution to what should
>>> be something simple and instead of the what I have read as 'If you
>>> pass an unsigned value greater than 2,147,483,647 to a LONG variable,
>>> the value will be interperted as a negarive number.' instead I get the
>>> 'value overflow' result.
>>>
>>> What is the correct method for getting an unsigned LONG value into a
>>> VB Signed LONG?
>>
>> Well the trick there is, where are you getting the unsigned long?
>>
>> You can assign any supported value you want using hexidecimal
>> notation:
>>
>> Z = &HFFFFFFFF
>>
>> LFS
>
> Thanks for the reply (and to Bill McCarthy in other post).
>
> My task is to read in aircraft position data from a file built by a flight
> data recorder, FS recorder programmed by Matthias Neusinger who has kindly
> sent me the subroutines and data formats which is programmed in C which
> IIRC writes in Low Byte Order First, so in a four byte data block, the
> right-hand most byte block is the High Byte value.
>
> I think the problem is now sorted as I was converting and multiplying each
> byte then adding that subtotal value to a Long variable but now, just
> building the byte block and converting it at the end works.
>
> A very many thanks to you both.

You're welcome. Glad you got it sorted out


..
Author
23 Feb 2009 7:30 PM
Karl E. Peterson
Bill McCarthy wrote:
> You're welcome.

Anyone taking notes for the next edition of, "The Complete Idiot's Guide to
Gratuitous Post Count Inflation"?
--
..NET: It's About Trust!
http://vfred.mvps.org
Author
23 Feb 2009 8:00 PM
Henning
"Karl E. Peterson" <k***@mvps.org> skrev i meddelandet
news:OYzb50elJHA.1288@TK2MSFTNGP02.phx.gbl...
> Bill McCarthy wrote:
>> You're welcome.
>
> Anyone taking notes for the next edition of, "The Complete Idiot's Guide
> to Gratuitous Post Count Inflation"?
> --
> .NET: It's About Trust!
> http://vfred.mvps.org
>

Sorry, but I'm getting an overflow the index in the Decimal data type ;)

/Henning
Author
23 Feb 2009 8:10 PM
Karl E. Peterson
Henning wrote:
> "Karl E. Peterson" <k***@mvps.org> skrev ...
>> Bill McCarthy wrote:
>>> You're welcome.
>>
>> Anyone taking notes for the next edition of, "The Complete Idiot's Guide
>> to Gratuitous Post Count Inflation"?
>
> Sorry, but I'm getting an overflow the index in the Decimal data type ;)

Yeah, that's a very real danger when you *ignore* the terminal condition check!
--
..NET: It's About Trust!
http://vfred.mvps.org