Solved

Unsigned Short in VB?

Posted on 1998-07-10
6
1,546 Views
Last Modified: 2012-06-27
How do you have Unsigned Short in VB? I know this doesn't exist, but I'm porting some stuff from C to VB and I need this data type.
any ideas?
0
Comment
Question by:platiumstar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 2

Expert Comment

by:Jagar
ID: 1465448
Isn't it a Byte (if not what is the range)
0
 
LVL 6

Accepted Solution

by:
clifABB earned 20 total points
ID: 1465449
This is snipped from VB Books Online:

The following table lists common C language data types and their Visual Basic equivalents for 32-bit versions of Windows.

C language      In Visual Basic            Call with
data type      declare as
INT, UINT      ByVal variable As Long      An expression that evaluates to a Long
0
 
LVL 6

Expert Comment

by:clifABB
ID: 1465450
That having been said, personally I would use a structure:
Type tUShort
  MSB As Byte
  LSB As Byte
End Type
Dim UShort as tUShort
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:platiumstar
ID: 1465451
I guess the worst comes to worst, I'll have to use that tUShort as you suggested. but I'm trying to avoid it as much as possible.

Although the document tell you to declare uint in C as long in VB, it doesn't tell you what to do with unsigned short, I declared it as just integer, but too many problems when doing network stuff where you have to shift the bits around.

for example: when I do
htons(PortNumber) where PortNumber = 2001, it gave me the value of -12025. Now this convert to hex is FFFF7D10, which would be correct if not for the FFFF part. This really bites.


0
 
LVL 6

Expert Comment

by:clifABB
ID: 1465452
I grabbed the wrong line in the Books Online file.
That should have been:
SHORT      ByVal variable As Integer      An expression that evaluates to an Integer

If you don't want to use tUShort, you can convert find it's true value with this code:
Dim lTrueVal As Long
If nShort >= 0 then
  lTrueVal = CLng(nShort)
Else
  lTrueVal = 32767 + Abs(CLng(nShort))
End If
0
 

Author Comment

by:platiumstar
ID: 1465453
thanks, I'll  give it a shot.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month10 days, 14 hours left to enroll

631 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question