PxPlus User Forum

Twitter Twitter Twitter

Author Topic: Trapping error with DTE()  (Read 1581 times)

JimGwynn

  • Member
  • **
  • Posts: 16
    • View Profile
Trapping error with DTE()
« on: February 14, 2020, 03:01:59 PM »
I am attempting to trap error generated by the DTE() command

Example = I know the data is bad but that is what I am trying to catch
0010 LET OUTDT$="40129C0"
0020 LET DT$=DTE(MID(OUTDT$,1,2)+"/"+MID(OUTDT$,3,2)+"/"+MID(OUTDT$,5,2):"%Mz/%Dz/%Yl",ERR=*NEXT)
0030 PRINT OUTDT$

Does not trap Error #41

 



Dave Fullerton

  • Silver Member
  • ***
  • Posts: 35
    • View Profile
Re: Trapping error with DTE()
« Reply #1 on: February 14, 2020, 03:23:29 PM »
Hi:

The error gets trapped, you're just sending it automatically to the next line:

0010 let outdt$="40129C0"
0020 let dt$=dte(mid(outdt$,1,2)+"/"+mid(outdt$,3,2)+"/"+mid(outdt$,5,2):"%Mz/%Dz/%Yl",err=BAD_DATE)
0030 print outdt$
0100 BAD_DATE:! ^100,5
0110 print err
0120 escape

I hope this helps

Regards

Dave

Mike King

  • Diamond Member
  • *****
  • Posts: 3810
  • Mike King
    • View Profile
    • BBSysco Consulting
Re: Trapping error with DTE()
« Reply #2 on: February 14, 2020, 03:58:20 PM »
If what you want to do is validate the date and you are running PxPlus 2018 or newer, simply use the JUL function as in:

X=JUL(DateString$, DateFormat$,ERR=Error_Branch)

For example, all the following will fail:

JUL("40129C0","MMDDYY") ! Length wrong
JUL("131290", "MMDDYY") ! Month 30 is bad
JUL("022919", "MMDDYY") ! Not a leap Year


These will work:

JUL("022819","MMDDYY")
JUL("02/28/19","MM/DD/YY")
JUL("02-28-2019","MM-DD-YYYY")
JUL("02/28/2019","MM-DD-YYYY") ! The parser doesn't care what non-numeric delimiter you use


Mike King
President - BBSysco Consulting
eMail: mike.king@bbsysco.com

JimGwynn

  • Member
  • **
  • Posts: 16
    • View Profile
Re: Trapping error with DTE()
« Reply #3 on: February 14, 2020, 04:28:10 PM »
Hi:

The error gets trapped, you're just sending it automatically to the next line:

0010 let outdt$="40129C0"
0020 let dt$=dte(mid(outdt$,1,2)+"/"+mid(outdt$,3,2)+"/"+mid(outdt$,5,2):"%Mz/%Dz/%Yl",err=BAD_DATE)
0030 print outdt$
0100 BAD_DATE:! ^100,5
0110 print err
0120 escape

I hope this helps

Regards

Dave

What is happening to me is it does not get to the next lines - Throws and Error #41.

John_S

  • Silver Member
  • ***
  • Posts: 20
    • View Profile
Re: Trapping error with DTE()
« Reply #4 on: February 14, 2020, 04:52:45 PM »
It traps the error for me, so I am not sure why it is throwing an error for you.  Here is my test code.  When I run it I get "bad date, error 41".

00010  LET OUTDT$="40129C0"
00020  LET DT$=DTE(MID(OUTDT$,1,2)+"/"+MID(OUTDT$,3,2)+"/"+ \
             MID(OUTDT$,5,2):"%Mz/%Dz/%Yl",ERR=0050)
00030  PRINT DT$
00040  ESCAPE
00050  PRINT "bad date, error ",ERR
00060  ESCAPE