Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. overFlow...

overFlow...

Scheduled Pinned Locked Moved Visual Basic
helpquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Anonymous
    wrote on last edited by
    #1

    hi, all The following code giving me an overflow error. Please tell me what is wrong in code. Private Sub Command1_Click() Dim x As Long Dim y As Integer y = 10 x = 11025 * y MsgBox x End Sub

    S 1 Reply Last reply
    0
    • A Anonymous

      hi, all The following code giving me an overflow error. Please tell me what is wrong in code. Private Sub Command1_Click() Dim x As Long Dim y As Integer y = 10 x = 11025 * y MsgBox x End Sub

      S Offline
      S Offline
      SimonS
      wrote on last edited by
      #2

      VB6 question right?

      Dim x As Long
      Dim y As Integer
      y = 10
      x = CLng(11025) * y
      MsgBox x

      Works fine. But, so does this:

      Dim x As Long
      Dim y As Integer
      y = 10
      x = 11025 * CLng(y)
      MsgBox x

      By using 2 integers as operands, the compiler is presuming that the result will also be an integer. Cheers, Simon "Sign up for a chance to be among the first to experience the wrath of the gods.", Microsoft's home page (24/06/2002)

      A 1 Reply Last reply
      0
      • S SimonS

        VB6 question right?

        Dim x As Long
        Dim y As Integer
        y = 10
        x = CLng(11025) * y
        MsgBox x

        Works fine. But, so does this:

        Dim x As Long
        Dim y As Integer
        y = 10
        x = 11025 * CLng(y)
        MsgBox x

        By using 2 integers as operands, the compiler is presuming that the result will also be an integer. Cheers, Simon "Sign up for a chance to be among the first to experience the wrath of the gods.", Microsoft's home page (24/06/2002)

        A Offline
        A Offline
        Anonymous
        wrote on last edited by
        #3

        hi,Simon thanks for your reply but,take this code, it is working fine with out using any type conversion Please.. Dim x As Long Dim y As Integer y = 10 x = 55555 * y MsgBox x

        S 1 Reply Last reply
        0
        • A Anonymous

          hi,Simon thanks for your reply but,take this code, it is working fine with out using any type conversion Please.. Dim x As Long Dim y As Integer y = 10 x = 55555 * y MsgBox x

          S Offline
          S Offline
          SimonS
          wrote on last edited by
          #4

          I don't have MSDN for VS6, but the upper limit for an integer is ~32,000, so in your example the "55,555" value is seen as a VB Long. Basically, it's like this: a. long = long * integer b. integer = integer * integer Your example corresponds to "a" and your initial post is like "b". The reason that "b" gave an overflow is that there's the potential for the product of 2 integers to exceed the max value for an integer (the compiler does it's best). HTH Cheers, Simon "Sign up for a chance to be among the first to experience the wrath of the gods.", Microsoft's home page (24/06/2002)

          A 1 Reply Last reply
          0
          • S SimonS

            I don't have MSDN for VS6, but the upper limit for an integer is ~32,000, so in your example the "55,555" value is seen as a VB Long. Basically, it's like this: a. long = long * integer b. integer = integer * integer Your example corresponds to "a" and your initial post is like "b". The reason that "b" gave an overflow is that there's the potential for the product of 2 integers to exceed the max value for an integer (the compiler does it's best). HTH Cheers, Simon "Sign up for a chance to be among the first to experience the wrath of the gods.", Microsoft's home page (24/06/2002)

            A Offline
            A Offline
            Anonymous
            wrote on last edited by
            #5

            thankQ i got the Point.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups