6

In order to settle a bet with one of my colleagues, I would like to find out if VB6 natively supports any unsigned data types.

I believe the answer to be "no", but I can't seem to find any official documentation confirming that. A simple link to a Microsoft document would be an acceptable answer; an historical justification as to why such types are not supported would be an added bonus.

Fueled
  • 8,776
  • 9
  • 29
  • 31
  • 2
    I know that VBA does not support it when you do COM interop: unsigned types are not part of OLE types. I'm not sure for VB6. – Alexandre C. Feb 02 '11 at 13:52
  • 3
    I suspect that unsigned numbers are unsupported in VB for the same reason they're unsupported in most other languages: they're rarely necessary. – Gabe Feb 02 '11 at 13:52
  • The only supported unsigned integer in Automation is Byte (unsigned char) – wqw Feb 02 '11 at 16:54

5 Answers5

9

As Kris said, they're not supported, except for the Byte datatype, which is only available as unsigned, as can be seen in this list of datatypes: Data Type Summary

The page mentions VBA, but it also mentions Visual Studio 6.0, and the supported data types were the same.

I don't think you'll find official documentation saying why they didn't add unsigned data types since that's usually the wrong way around in that it probably wasn't a case of "why shouldn't we support this" as much as "would it be worth the extra effort to add this".

Edited to mention the exception of the Byte datatype as pointed out by MarkJ.

Hans Olsson
  • 54,199
  • 15
  • 94
  • 116
  • As I'm mostly ignorant regarding the history of programming languages, I assumed that the data types for VB were based roughly on those of C. But as I just found out on Wikipedia, VB is based on BASIC, which was developed before C (both in the 60's though). – Fueled Feb 02 '11 at 14:15
  • Well, the VB stands for "Visual Basic" after all, though it's not often I see the full name written out so if you haven't worked with it, you might not have seen that. – Hans Olsson Feb 02 '11 at 14:30
  • 3
    +1 for linking to the right page. However a careful reading of that page shows that VB6 supports **one** unsigned datatype: `Byte` which is an unsigned 1-byte integer, like the C `char`. VB6 also has `Integer`, `Long` and `Currency` which are signed 2-byte, 4-byte and (scaled) 8-byte integers respectively. – MarkJ Feb 03 '11 at 09:26
  • @MarkJ: I forgot about the Byte, thanks for reminding me and I've updated my answer to reflect this. – Hans Olsson Feb 03 '11 at 09:45
2

The only unsigned integer type is Byte.

Bob77
  • 13,167
  • 1
  • 29
  • 37
1

There is the option of passing hex values into a Long type which would be stored as unsigned as long as the sign bit is not part of the value. so for example,

&HFFFF = -1 

but &HFFFF& = 65535 

note that these 16bit vals are passed into a Long type, which is 32bits. so the sign bit is untouched. but if you need 32bits one suggestion was to use type Double, someone mentioned it before.

Regarding the need for unsigned types in general, an Unsigned Long would be a 32bit binary, compared to a Byte that is only 8bits. Try to write 24bit registers via a serial port with Byte types.. :) my take is that in VBA the sign bit sits like a splinter in the way of bit logic..

in any case, I hope this helps someone.

cheers,

Norwood, MA

Pragnesh Chauhan
  • 8,363
  • 9
  • 42
  • 53
oneMate
  • 11
  • 1
0

Not supported.

Some good info regarding simulating them: http://www.vbforums.com/showthread.php?t=578430

Kris
  • 1,789
  • 3
  • 18
  • 27
  • I had already found the exact same thread, but I would really like to see the official Microsoft documentation that says why are unsigned types not supported. – Fueled Feb 02 '11 at 13:58
0

No not supported for VB6 ,it was added as explained at this link in VB.NET.

DesignFirst
  • 329
  • 2
  • 5