Solved

Unsigned Short in VB?

Posted on 1998-07-10
6
1,539 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
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
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
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…

821 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