Results 1 to 5 of 5

Thread: This is strange...

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2000
    Posts
    52

    Post

    ...to me at least. The experienced among you will probably know what's up immediately.

    Anyways, here's the situation:

    module-1

    global buffer as long
    public const MAX_XRES= 800
    public const MAX_YRES= 600

    form-1

    buffer= MAX_XRES * MAX_YRES

    THIS CAUSES AN OVERFLOW ERROR (6)

    800*600 (480000) > 2^32 ???!!

    If I simply say:

    buffer= 480000, there's no problem

    Obviously, VB is playing some odd type conversion game; if anyone can tell me exactly what's going on here, I'd really appreciate it.

    Thanks

  2. #2
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845

    Post

    I expect someone else will explain why it does it but this works

    Code:
    Public buffer As Long
    Public Const MAX_XRES As Long = 800
    Public Const MAX_YRES As Long = 600
    ------------------
    Mark Sreeves
    Analyst Programmer

    [email protected]
    A BMW Group Company



  3. #3
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840

    Post

    That's right, use Public. Global I beleive is for Global objects in classes (class modules)

  4. #4
    New Member
    Join Date
    Jan 2000
    Posts
    8

    Post

    Hi!

    By default MAX_XRES and MAX_YRES are Integer.
    As result when VB uses temp variable you have
    Overflow! Just try:

    public const MAX_XRES= 800.0
    public const MAX_YRES= 600.0
    In this case VB will use by default Single

    HTH

  5. #5

    Thread Starter
    Member
    Join Date
    Feb 2000
    Posts
    52

    Post

    Thanks everyone. I figured it was something like that. VB "ought" to be smart enough to know that an integer multiplied by an integer will have to be held in a long. Can't everything, I guess.

Posting Permissions

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



Click Here to Expand Forum to Full Width