Solved

Unsigned Short in VB?

Posted on 1998-07-10
6
1,526 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
  • 3
  • 2
6 Comments
 
LVL 2

Expert Comment

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

Accepted Solution

by:
clifABB earned 20 total points
Comment Utility
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
Comment Utility
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:platiumstar
Comment Utility
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
Comment Utility
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
Comment Utility
thanks, I'll  give it a shot.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now