Solved

Unsigned Short in VB?

Posted on 1998-07-10
6
1,533 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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

773 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