Consulting

Results 1 to 5 of 5

Thread: Overflow error.

  1. #1
    VBAX Newbie
    Joined
    Feb 2014
    Posts
    2
    Location

    Overflow error.

    Hi. Fairly new to VBA coding and having trouble with this macro. Gives me an overflow error, but since I am new I have no idea what that is or how to fix it. Any help?Chapter 4 Math.xlsm

  2. #2
    overflow error means a value is being assigned to a variable that is not big enough to hold the value, change the type of your variable, or use type casting for calculations

    post which code is causing the error and when it happens

  3. #3
    VBAX Newbie
    Joined
    Feb 2014
    Posts
    2
    Location
    Here it is.

    Private Sub MathGame()
    'Manages the clocl while testing. Calls scoring procedures when test is over.
        Dim numSeconds As Integer
        Dim nextTime As Date
        Const TIMEALLOWED = 60
        
        numSeconds = DateDiff("s", curDate, Now)
        '---------------------
        'Start the clock.
        '---------------------
        Range("Clock").Value = TIMEALLOWED - numSeconds
        nextTime = Now + TimeValue("00:00:01")
        Application.OnTime EarliestTime:=nextTime, _
        Procedure:="MathGameSheet.MathGame", Schedule:=True

  4. #4
    what would be the value of curdate when the procedure runs, somthing over 9 hours in seconds is the maximum an integer can hold, try changing to a long

  5. #5
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    ...nor does curDate appear to be defined/declared in the posted snippet. You are very most likely safe in declaring anything (save some particular args passed to API if present) you have as an Integer, as a Long.

Posting Permissions

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