Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Overflow error using a CVDate function

Status
Not open for further replies.

coswa

Technical User
Jun 16, 2008
7
US
I'm getting an overflow error from a CVDate function. I have no idea what's causing it ... when I write a test program using input boxes instead of getstring, etc it works fine. I'm sure that there is something I did earlier in the listing that's messing it up somehow, but i really can't say what it is.

And oh, it's not just the constructed string variable causing the overflow error; swapping around the dat1= and dat2= lines just causes it to crash at the first use.

Thank you.

Code:
Sub Main
    dim sys as Object, sess as Object, xl as Object, wb as Object, nwb as object
    dim notes1() as string, notes2() as string
    dim icount as integer, jcount as integer, xlcount as integer, kcount as integer
    dim notetype as string, quit as integer, notedat as string
    dim acct as string, age as integer
    dim dat1 as integer, dat2 as integer
    dim aday as string, amonth as string, ayear as string, newmonth as string

    'GET ACCESS TO THE TOP LEVEL E!PC OBJECT...
    set sys = CreateObject("Extra.System")
    if sys is nothing then
        msgbox("Could not create Extra.System...is E!PC installed on this machine?")
        exit sub
    end if
    
    'GET ACCESS TO THE CURRENTLY ACTIVE SESSION...
    set sess = sys.ActiveSession
    if sess is nothing then
        msgbox("No session available...stopping macro playback.")
        exit sub
    end if
    
    'MAKE SURE THE ACC SCREEN IS ACTIVE
    cond=sess.Screen.GetString(1,45,3)
    if cond <> "ACC" then
        msgbox("Please manuever to ACC screen and try again")
        exit sub
    end if
    
    set xl = CreateObject("Excel.Application")
    if xl is nothing then
        msgbox("Could not create Excel.Application...is Excel installed on this machine?")
        exit sub
    end if
    
    sFile = xl.getopenfilename 
    set wb = xl.Workbooks.Open(sFile)
    
    
    redim notes1(1)
    redim notes2(1)
    notes1(1)="ACCT"
    notes2(1)="NOTES"
    
    xlcount=1
    icount=2
    Do
        if wb.worksheets("sheet1").cells(icount,1)="" then
            exit Do
        end if
        acct=wb.worksheets("sheet1").cells(icount,1)
        if left(acct,1)<>"0" then
            acct="0"&acct
        end if
        sess.screen.moveto 4,11
        sess.screen.waitforcursor 4,11
        sess.screen.sendkeys(acct)
        sess.screen.sendkeys("<enter>")
        sess.screen.waithostquiet(0)
        
        
        quit=0
        'DETERMINE IF NOTES ARE PERMAMENT OR GENERAL, THEN SEARCH DOWN FOR GENERAL NOTES LESS THAN SEVEN DAYS OLD
'''''''''ADD CHECK FOR ALL P TYPE NOTES ON A SCREEN AND RELOOP
        for jcount=7 to 41
            notetype=sess.screen.getstring(jcount,2,1)
            Select Case notetype
                case "P"
                case "G"
                    aday=trim(sess.screen.getstring(jcount,4,2))
                    amonth=trim(sess.screen.getstring(jcount,7,3))
                    ayear=trim(sess.screen.getstring(jcount,11,2))
                    select case amonth
                        case "JAN"
                            newmonth="01"
                        case "FEB"
                            newmonth="02"
                        case "MAR"
                            newmonth="03"
                        case "APR"
                            newmonth="04"
                        case "MAY"
                            newmonth="05"
                        case "JUN"
                            newmonth="06"
                        case "JUL"
                            newmonth="07"
                        case "AUG"
                            newmonth="08"
                        case "SEP"
                            newmonth="09"
                        case "OCT"
                            newmonth="10"
                        case "NOV"
                            newmonth="11"
                        case "DEC"
                            newmonth="12"
                    end select
                    notedat = newmonth & "/" & aday & "/" & ayear
                    
                    dat1 = CVDate(notedat)
                    dat2 = CVDate(date)
                    age = dat2 - dat1
                    if abs(age) > 7 then
                        quit=1
                    else
                        xlcount=xlcount + 1
                        redim preserve notes1(xlcount)
                        redim preserve notes2(xlcount)
                        notes1(xlcount)=acct
                        notes2(xlcount)=sess.screen.getstring(jcount,19,62)
                    end if
                case else
                    quit=1
            end select
            if quit=1 then
                exit for
            end if
        next jcount
        icount=icount+1
        
    Loop
    
    set nwb = xl.Workbooks.Add
    
    for icount=1 to xlcount
        nwb.worksheets("sheet1").cells(icount,1)=notes1(icount)
        nwb.worksheets("sheet1").cells(icount,2)=notes2(icount)
    next icount
    xl.visible = true
    
        
End Sub
[end code]
 


set sys = CreateObject("Extra.System")
What application are you coding this in? Not in Extra, it seems.

Please identify the statement that is throwing the error.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
I am coding from attachmate: I'm exporting info to excel at the moment to research a parser for a notes screen. The set sys= CreateObject("Extra.System") statement is part of the boilerplate for setting up objects -- I've never had any problems with this on any other script before.

the lines that are causing the problems are
Code:
                    dat1 = CVDate(notedat)
                    dat2 = CVDate(date)

It doesn't appear to be any sort of formatting/variable type problem on the dat1 variable, as I get an Overflow error on the earliest line if I swap the two lines around. I've tested with input boxes with this code
Code:
Sub main()
    Dim str1, str2, str3, test As String
    Dim dat1, dat2, daysnum As Integer
    
    str1 = InputBox("day")
    str2 = inputbox("month")
    str3 = inputbox("year")
    
    select case str2
        case "JAN"
            amonth="01"
        case "FEB"
            amonth="02"
        case "MAR"
            amonth="03"
        case "APR"
            amonth="04"
        case "MAY"
            amonth="05"
        case "JUN"
            amonth="06"
        case "JUL"
            amonth="07"
        case "AUG"
            amonth="08"
        case "SEP"
            amonth="09"
        case "OCT"
            amonth="10"
        case "NOV"
            amonth="11"
        case "DEC"
            amonth="12"
    end select
    test = amonth & "/" & str1 & "/" & str3
    
    dat1 = CVDate(test)
    
    dat2 = CVDate(Date)
    daysnum = dat2 - dat1
    MsgBox daysnum
End Sub

and it works fine. While I hope that the error is something simple and straightforward, I have a feeling that it's not.

Thanks,
chris

ps. I did get the use of the CVDate function from one of your earlier posts. Thanks for that one, too



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top