Fun VB Challenge :)

AceInfinity

Emeritus, Contributor
Joined
Feb 21, 2012
Posts
1,728
Location
Canada
Here's a nice little challenge for you guys (I already know the answer, because I answered this for a question on a different forum).

Before we begin, you must know that 0xFFFFFFFF and 4294967295 are equal values

Question: Why will this work:
Code:
Dim i As UInteger = 4294967295

But this will not:
Code:
Dim i As UInteger = &HFFFFFFFF

???

:thumbsup2:
 
It's because visual studio treats the literal &HFFFFFFFF as an integer data type giving it the value -1 which is not a valid UInteger value. To use the number, you must force visual studio to treat it as a UInteger by appending the forced literal type UI to the end.

To make it harder you shouldn't have said you answered it on another forum. Google is our friend.

http://msdn.microsoft.com/en-us/library/s9cz43ek.aspx
 
Last edited by a moderator:
http://tech.reboot.pro/showthread.php?tid=2776&pid=22540#pid22540 said:
&H is a numeric base identifier for a hexadecimal value, not a string, the & doesn't really have much of a definition in VB, especially to represent "And" or "AndAlso". (Other than being a sufix for Long)

There you go. :p
 
lol, you cheaters :hysterical:

For a hexadecimal value though it's still denoted as an Integer type, and the max value for an integer is 2147483647, max value for a UInteger is 4294967295, therefore, since hexadecimal values prefixed with &H are interpretted as Integer values, the value of &HFFFFFFFF which is 4294967295, is invalid as an integer as a 32 bit integer has a max of 2147483647, so the compiler evaluates it as -1, and as a UInteger (no negatives), this is invalid, and not assignable. Therefore you could suffix it with UI, to declare it as an unsigned 32 bit integer, OR suffix it with '&' to declare it as a Long (64 bit signed integer) which has a max value of 9223372036854775807, but extends into the negative values as well unlike an unsigned 32 bit integer value. If denoted as an Unsigned 64 bit integer, the max value would be: 18446744073709551615
 
Ace
You didnt say we couldnt {grin}.

I bow to programmers. I did it for far longer than I care to remember.
 
VB is pretty simplistic, almost secondary to the English language because contrary to the programming languages with brackets, VB puts everything into effect with common English words, which makes it much easier to understand for the beginner programmer, or somebody just starting out. C# and C++ are 2 of my favorites though i'll admit, for compile-able languages. Aside from Assembly which is something i've recently got more in depth with.
 
Although I couldn't stand having to type the utterly redundant Then after an If statement. Plus I hated having to type out End Sub all the time, rather than just a } or whatever. VB was just too wordy for me, hence I quickly moved to C#.
 
I'd prefer other languages too, but being that VB is so popular i'm still 'required' to know it so I can help others when they need it.
 
I'd prefer other languages too, but being that VB is so popular i'm still 'required' to know it so I can help others when they need it.

Indeed. I actually end up helping more people with VB than I do C# on these forums. lol.
 
haha, SEE what I mean :) But that's not a bad thing, as much as I enjoy just programming in general, I enjoy just as well, helping others.

See, and the thing is, the things i'm currently working on, I highly doubt, and can nearly guarantee most people here do not know a single thing about my SIMPL programming with SIMPL+ or SIMPL Windows.
 

Has Sysnative Forums helped you? Please consider donating to help us support the site!

Back
Top