+ Reply to Thread
Results 1 to 4 of 4

[SOLVED] Overflow.....when the instruction above the overflow is a bigger value????!!

  1. #1
    Forum Contributor
    Join Date
    06-16-2011
    Location
    London
    MS-Off Ver
    Excel XP
    Posts
    276

    [SOLVED] Overflow.....when the instruction above the overflow is a bigger value????!!

    Cutting a long story short, I've got some code that takes a large binary value, converts it into decimal and then converts it again into a base 27 number (using A as 1, B as 2, etc) so that I've got a 6 digit "code".

    This all works fine and the biggest value I'll need to deal with is somewhere in the region of 134million, the largest output code I'm ever gonna have is: "IINZBZ".

    I've just started testing to write the routine to decode it back into a binary value and I'm getting a very odd problem.


    Please Login or Register  to view this content.

    I dont understand.

    The value directly above the command which gives an overflow outputs a value of 4,782,969.
    The command that gives an overflow is only a value of 275,562.

    I'm sure this'll be something stupid and obvious but......damned if my addled old brain can see it.
    Last edited by swoop99; 12-29-2011 at 08:08 AM.

  2. #2
    Forum Contributor
    Join Date
    06-16-2011
    Location
    London
    MS-Off Ver
    Excel XP
    Posts
    276

    Re: Overflow.....when the instruction above the overflow is a bigger value????!!

    God I hate VBA.


    ok, because the * by value is less than 32000 VBA assumes it's an integer and not a long so the output is way over the biggest number an integer data type can handle.

    changing the command to: MsgBox (Asc(Mid$(hcode, 3, 1)) - 64) * 19683&
    fixes the problem.

    I knew it'd be stupid.
    Last edited by swoop99; 12-29-2011 at 08:08 AM.

  3. #3
    Forum Contributor
    Join Date
    12-28-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    280

    Re: Overflow.....when the instruction above the overflow is a bigger value????!!

    I may be completely wrong here but I suspect that when VBA compiles the code it notes that the value of 19683 fits within the integer datatype and thus assigns this data type to the result of the calculation (which therefore produces the overflow). Why it does this I don't know.

    You can avoid it by eg using the Long type declaration character on the end of the value so VBA knows not to squeeze it into an integer:

    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    06-16-2011
    Location
    London
    MS-Off Ver
    Excel XP
    Posts
    276

    Re: Overflow.....when the instruction above the overflow is a bigger value????!!

    Ta for the reply firefly, I think I figured it out as you were typing. Marking thread as solved and hopefully it'll solve some other poor sap's issue with VBA being daft.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1