1. #1
    AceInfinity's Avatar
    Join Date
    Feb 2012
    Location
    Canada
    Posts
    1,716

    Fun VB Challenge :)

    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
    ???

    zigzag3143 says thanks for this.
    \n\n

    Automation Programmer
    Development Site: aceinfinity.net


    • Ad Bot

      advertising
      Beep.

        
       

  2. #2
    zigzag3143's Avatar
    Join Date
    Mar 2012
    Posts
    3,741
    • specs System Specs
      • Manufacturer:
        HP
      • Model Number:
        DV7
      • Cooling:
        Coolermaster U3 best in class
      • Operating System:
        Win 8 RTM

    Re: Fun VB Challenge :)

    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 JMH; 06-05-2012 at 03:37 AM. Reason: Typo

    MS-MVP Windows IT-PRO 2010-2017
    MCC-2013-2017
    Wankiya & Dyami
    Team ZigZag





  3. #3
    JaidynM's Avatar
    Join Date
    May 2012
    Location
    Somewhere Over The Rainbow
    Posts
    1,011
    • specs System Specs
      • Manufacturer:
        Custom Build
      • Motherboard:
        ASUS P5G41T-M LX
      • CPU:
        Intel Pentium Dual Core E6700 3.2GHz
      • Memory:
        Strontium 8192MB DDR3 1333Mhz
      • Graphics:
        msi GeForce N560GTX-M2D1GD5 1GB
      • Sound Card:
        Realtek HD Audio
      • Hard Drives:
        Seagate Barracuda LP Green 2TB Internal HDD + WD Elements Desktop 1TB External HDD
      • Disk Drives:
        Black eMaxx ATX Mini Tower Case
      • Power Supply:
        SHAW Viper-1500w Gaming PSU
      • Display:
        CHIMEI CMV 221D 22" (1680x1050)
      • Operating System:
        Windows 7 Ultimate x64/Windows 8 Consumer Preview x64/Ubuntu 11.04

    Re: Fun VB Challenge :)

    Quote Originally Posted by http://tech.reboot.pro/showthread.php?tid=2776&pid=22540#pid22540
    &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.
    zigzag3143 says thanks for this.

    "No bird soars to high, if he soars with his own wings." - William Blake


  4. #4
    AceInfinity's Avatar
    Join Date
    Feb 2012
    Location
    Canada
    Posts
    1,716

    Re: Fun VB Challenge :)

    lol, you cheaters

    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
    zigzag3143 and JaidynM say thanks for this.
    \n\n

    Automation Programmer
    Development Site: aceinfinity.net

  5. #5
    zigzag3143's Avatar
    Join Date
    Mar 2012
    Posts
    3,741
    • specs System Specs
      • Manufacturer:
        HP
      • Model Number:
        DV7
      • Cooling:
        Coolermaster U3 best in class
      • Operating System:
        Win 8 RTM

    Re: Fun VB Challenge :)

    Ace
    You didnt say we couldnt {grin}.

    I bow to programmers. I did it for far longer than I care to remember.
    AceInfinity says thanks for this.

    MS-MVP Windows IT-PRO 2010-2017
    MCC-2013-2017
    Wankiya & Dyami
    Team ZigZag





  6. #6
    AceInfinity's Avatar
    Join Date
    Feb 2012
    Location
    Canada
    Posts
    1,716

    Re: Fun VB Challenge :)

    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.
    \n\n

    Automation Programmer
    Development Site: aceinfinity.net

  7. #7
    GZ's Avatar
    Join Date
    Apr 2012
    Location
    New Jersey
    Posts
    1,923
    • specs System Specs
      • Manufacturer:
        GZ Technologies LLC
      • Model Number:
        Phenom-INAL
      • Motherboard:
        ASUS M5A97-EVO
      • CPU:
        AMD PhenomII x6 (1100T)
      • Memory:
        16GB Kingston Hyper-X blu PC3-12800
      • Graphics:
        XFX Radeon HD6770
      • Sound Card:
        Realtek ALC892
      • Hard Drives:
        500GB WD Caviar Black / 1TB WD Caviar Black / 1TB Seagate / 500GB Hitachi
      • Disk Drives:
        HP DVD 1270i SATA DVD RW
      • Power Supply:
        Corsair 850TX
      • Case:
        Antec 300
      • Cooling:
        Coolermaster V8 / 2x 12CM intake / 1x 12CM rear exhaust / 1x 14CM top exhaust
      • Display:
        Acer 23in 1920x1080 / Acer 20in
      • Operating System:
        Microsoft Windows 8 Professional x64

    Re: Fun VB Challenge :)

    Yay for VB!!!

    "Among the tales of sorrow and of ruin that come down to us from the darkness of those days there are yet some in which amid weeping there is joy and under the shadow of death light that endures."

    J.R.R. Tolkien - The Silmarillion

  8. #8
    niemiro's Avatar
    Join Date
    Mar 2012
    Location
    District 12
    Posts
    7,827

    Re: Fun VB Challenge :)

    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#.

  9. #9
    AceInfinity's Avatar
    Join Date
    Feb 2012
    Location
    Canada
    Posts
    1,716

    Re: Fun VB Challenge :)

    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.
    \n\n

    Automation Programmer
    Development Site: aceinfinity.net

  10. #10
    niemiro's Avatar
    Join Date
    Mar 2012
    Location
    District 12
    Posts
    7,827

    Re: Fun VB Challenge :)

    Quote Originally Posted by AceInfinity View Post
    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.

  11. #11
    AceInfinity's Avatar
    Join Date
    Feb 2012
    Location
    Canada
    Posts
    1,716

    Re: Fun VB Challenge :)

    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.
    \n\n

    Automation Programmer
    Development Site: aceinfinity.net

Similar Threads

  1. Programming Challenge!
    By AceInfinity in forum Programming
    Replies: 9
    Last Post: 09-10-2015, 10:38 PM
  2. Replies: 0
    Last Post: 02-17-2013, 07:52 PM
  3. Fun with statistics: Who hates Java the most?
    By JMH in forum News You Can Use
    Replies: 0
    Last Post: 01-15-2013, 06:33 PM
  4. Fun with MDLs
    By Vir Gnarus in forum BSOD Kernel Dump Analysis Debugging Information
    Replies: 0
    Last Post: 03-16-2012, 10:49 AM

Log in

Log in