Unusal overflow error, can you help?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • KoRMaK
    New Member
    • Nov 2011
    • 1

    Unusal overflow error, can you help?

    I am creating a program which will find a function maximum to give a profit. This profit function is equiped with an error function to prevent ordering more stock than can be obtained.

    The function itself is in excel and is only used as a value in VB.
    Code:
       
        xa = 90
        xb = 90
        Cells(6, 5).Value = xa
        Cells(7, 5).Value = xb
        
        Profit = Cells(4, 9).Value
        
    
    For i = 1 To 1000
    
        xan = xa + dxa * (2 * Rnd() - 1)
        
    Cells(6, 5).Value = xan
    
        xbn = xb + dxb * (2 * Rnd() - 1)
       
        
        Cells(7, 5).Value = xbn
      
        [U]Profitn = Cells(4, 9).Value[/U]
        
        
    
    If (xan >= xlow) And (xan <= xahi) And (xb <= xbhi) And (xb >= xlow) And (Profitn > Profit) Then
    
        xa = xan
        xb = xbn
        Profit = Profitn
    
        Cells(6, 9).Value = xa
        Cells(7, 9).Value = xb
        
        Cells(5, 9).Value = Profit
        
    End If
    
    Next
    The underlined section is where the debug is showing a problem.

    Any help would be greatly appreciated
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    It's probably overflowing the data type of profitn. Whatever that is, your code doesn't have that info.

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      Yes, I think we need to know the format of profitn, and the value you're trying to place in it.

      One question though, just to be sure - are profit and profitn two different variables (or a variable and the function name), or is one a typo?

      Comment

      Working...