Solved

Unsigned Short in VB?

Posted on 1998-07-10
6
1,542 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
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…

734 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