472,127 Members | 1,601 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,127 software developers and data experts.

The missing C++ unsigned short integer in VB6

C++ has a variable type 'unsigned short int.' I am trying to write a VB6
program that prints these out of a file made originally by C++. However,
the unsigned short integer (1-65535) is not supported. Does anyone have a
routine that will allow VB6 to read a C++ unsigned short int?

Thanks

Del
Jul 17 '05 #1
2 11030
you could read two single bytes from the file and use a function like:

Public Function MakeWord(msb As Byte, lsb As Byte) As Long
MakeWord = CLng("&h" & Trim$(Hex(msb)) & Trim(Hex(lsb)))
End Function

Function takes two bytes and makes a C++ short integer(word) 16bit
msb;Most significan byte, lsb;least signinficant byte, watch the byte order.

VB does not support Unsigned data type so must return a long

probably not the most efficient inplementation but serves as an example

hope it helps, any probs....
al.

"Salgoud Dell" <sa*****@nomail.com> wrote in message
news:<ca**********@news.cfu.net>...
C++ has a variable type 'unsigned short int.' I am trying to write a VB6
program that prints these out of a file made originally by C++. However,
the unsigned short integer (1-65535) is not supported. Does anyone have a
routine that will allow VB6 to read a C++ unsigned short int?

Thanks

Del

Jul 17 '05 #2
"Salgoud Dell" <sa*****@nomail.com> wrote in message news:<ca**********@news.cfu.net>...
C++ has a variable type 'unsigned short int.' I am trying to write a VB6
program that prints these out of a file made originally by C++. However,
the unsigned short integer (1-65535) is not supported. Does anyone have a
routine that will allow VB6 to read a C++ unsigned short int?


VB6 can read it into an Integer variable just fine. Values 32768 to
65535 will be displayed as -32768 to -1 but you can either just use
them that way or move the values to a Long and mask off the low 16
bits to see the original values.
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Vijay Kumar R Zanvar | last post: by
8 posts views Thread by avsrk | last post: by
4 posts views Thread by slougheed | last post: by
5 posts views Thread by wolverine | last post: by
1 post views Thread by wolverine | last post: by
10 posts views Thread by Jim Langston | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.