Why am I getting an Overflow error?

Discussion in 'OT Technology' started by Acoustyk, Jul 23, 2008.

  1. Acoustyk

    Acoustyk Jesus didn't save the dinosaurs lol

    Joined:
    May 31, 2007
    Messages:
    224
    Likes Received:
    0
    Location:
    The vicinity of Richmond, VA
    Case 1
    Do
    If x >= 23 And x < 28 Then
    i = "m"
    ElseIf x >= 29 And x < 35 Then
    i = "s"
    ElseIf x >= 35 And x < 41 Then
    i = "y"
    ElseIf x >= 41 And x < 47 Then
    i = "AE"
    ElseIf x >= 47 And x < 53 Then
    i = "AK"
    ElseIf x >= 53 And x < 59 Then
    i = "AQ"
    ElseIf x >= 59 And x < 65 Then
    i = "AW"
    End If


    Workbooks("weeklyreport.xls").Sheets("Timesheet").range(i & "19").Value = Workbooks("newapproach2replaced8updatesaveex.xls").Sheets("TimesheetRich").range("F" & x).Value 'Sunday / Holiday
    Workbooks("weeklyreport.xls").Sheets("Timesheet").range(i & "21").Value = Workbooks("newapproach2replaced8updatesaveex.xls").Sheets("TimesheetRich").range("y" & x).Value ' From - Work
    Workbooks("weeklyreport.xls").Sheets("Timesheet").range(i & "22").Value = Workbooks("newapproach2replaced8updatesaveex.xls").Sheets("TimesheetRich").range("ab" & x).Value ' Until - Work
    Workbooks("weeklyreport.xls").Sheets("Timesheet").range(i & "24").Value = Workbooks("newapproach2replaced8updatesaveex.xls").Sheets("TimesheetRich").range("AK" & x).Value ' Break time - Work
    Workbooks("weeklyreport.xls").Sheets("Timesheet").range(i & "33").Value = Workbooks("newapproach2replaced8updatesaveex.xls").Sheets("TimesheetRich").range("n" & x).Value ' From - Travel
    Workbooks("weeklyreport.xls").Sheets("Timesheet").range(i & "34").Value = Workbooks("newapproach2replaced8updatesaveex.xls").Sheets("TimesheetRich").range("q" & x).Value ' Until - Travel
    Workbooks("weeklyreport.xls").Sheets("Timesheet").range(i & "35").Value = Workbooks("newapproach2replaced8updatesaveex.xls").Sheets("TimesheetRich").range("v" & x).Value ' Break time - Travel
    'add worklist later

    x = x + 1
    If Workbooks("newapproach2replaced8updatesaveex.xls").Sheets("TimesheetRich").range("BF" & x).EntireRow.Hidden = True Then
    Do
    x = x + 1 <-----------overflow
    Loop Until Workbooks("newapproach2replaced8updatesaveex.xls").Sheets("TimesheetRich").range("BF" & x).EntireRow.Hidden = False And Workbooks("newapproach2replaced8updatesaveex.xls").Sheets("TimesheetRich").range("BF" & x).Value = 1
    End If
    Loop Until x = 64
    Workbooks("weeklyreport.xls").SaveAs "C:\" & pnumber & "_" & firstname & "_" & familyname & "_" & csnumber & "_" & calendarweek & "_" & year & ".xls", FileFormat:=xlNormal

    This is the code for my first case. This code is supposed to transfer data to another sheet but I keep getting an overflow error in the said location.
     
  2. apoptosis

    apoptosis allyourthreadsarebelongto me

    Joined:
    Apr 5, 2007
    Messages:
    787
    Likes Received:
    0
    what language is this ?
    cos this in not c nor c++
     
  3. dissonance

    dissonance reset OT Supporter

    Joined:
    May 23, 2006
    Messages:
    5,652
    Likes Received:
    1
    Location:
    KS
    I'm no help but would guess this is Excel VBA...
     
  4. Limp_Brisket

    Limp_Brisket New Member

    Joined:
    Jan 2, 2006
    Messages:
    48,422
    Likes Received:
    0
    Location:
    Utah
    maybe your loop isn't terminating
     
  5. Frequency

    Frequency New Member

    Joined:
    Dec 30, 2004
    Messages:
    7,504
    Likes Received:
    0
    Location:
    PA
    you are using x as a counter in nested loops and you are checking for when x = 64.
    When you hit your "loop until" x will always be an odd number when it checks to terminate the loop
     
  6. EkriirkE

    EkriirkE Zika Xenu OT Supporter

    Joined:
    Jan 11, 2004
    Messages:
    14,799
    Likes Received:
    0
    Location:
    Dublin & San Francisco, CA
    :werd: make that = 64 a >= 64
     
  7. CodeX

    CodeX Guest

    As was already stated, your outer loop is looking for a specific value of x (64) as the terminating condition, however you are sometimes incrementing x by 2 or more (depending on the number of iterations of the inner loop).

    I would suggest using two loop counters, perhaps x and y (I would use i,j for this). Test for x = 64, but in your inner loop increment y instead and use y instead of x to do whatever the hell that does (index an array?)

    Simply changing the terminating condition from x > 64 to x >= 64 will likely not give the desired result, if of course you actually intend the outer loop to iterate 64 times.

    like this:
    Code:
    x = x + 1
    
    If Workbooks("newapproach2replaced8updatesaveex.xls") Sheets("TimesheetRich").range("BF" & x).EntireRow.Hidden = True Then
        Do
           y = y + 1
        Loop Until Workbooks("newapproach2replaced8updatesaveex.xls") .Sheets("TimesheetRich").range("BF" & y).EntireRow.Hidden = False And Workbooks("newapproach2replaced8updatesaveex.xls") .Sheets("TimesheetRich").range("BF" & y).Value = 1
    End If
    
    Loop Until x = 64
    
    This is of course dependent on my understanding of what that hideous code is supposed to be doing... which isn't great lol
     

Share This Page