Results 1 to 4 of 4

Thread: overflow by 300 * 300

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    overflow by 300 * 300

    Hello

    I wonder if you can help me. l am trying to multipile 300 by 300, and get a overflow error. l have tried using a long, single and double datatype, but l am still getting the same problem.

    Many thanks in advance
    steve

  2. #2
    pathfinder NotLKH's Avatar
    Join Date
    Apr 2001
    Posts
    2,397
    Long works for me.


    VB Code:
    1. Private Sub Command1_Click()
    2.     Dim p1 As Long
    3.     Dim p2 As Long
    4.     Dim p3 As Long
    5.         p1 = 300
    6.         p2 = 300
    7.             p3 = p1 * p2
    8.                 MsgBox p3
    9. End Sub

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331
    That bit of code does work.

    If you use this code, you will get a overflow error

    Code:
    Private Sub Command1_Click()
        
        Dim p3 As Long
           
        p3 = 300 * 300
        MsgBox p3
    End Sub
    Do you know why this happens

    Many thanks in advance
    steve

  4. #4
    pathfinder NotLKH's Avatar
    Join Date
    Apr 2001
    Posts
    2,397
    Originally posted by steve_rm
    That bit of code does work.

    If you use this code, you will get a overflow error

    Code:
    Private Sub Command1_Click()
        
        Dim p3 As Long
           
        p3 = 300 * 300
        MsgBox p3
    End Sub
    Do you know why this happens

    Many thanks in advance
    This is what help says:

    Code:
    You attempt to use a number in a calculation, and that number is 
    coerced into an integer, but the result is larger than an integer. 
    For example: 
    
    VB Code:
    1. Dim x As Long
    2.     x = 2000 * 365   ' Error: Overflow
    To work around this situation, type the number, like this:
    VB Code:
    1. Dim x As Long
    2.     x = CLng(2000) * 365
    Now, as to why MSoft designed it that way, I don't know.
    Personally, I think its a design flaw.
    -Lou

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