home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.databases
- Path: sparky!uunet!almserv!mimas!g9utxu
- From: g9utxu@fnma.COM (Tanin Uthayanaka)
- Subject: Re: Pls help: algorithm wanted (xbase, pref foxpro)
- Message-ID: <1993Jan5.144438.15119@almserv.uucp>
- Sender: usenet@almserv.uucp
- Nntp-Posting-Host: mimas
- Reply-To: g9utxu@fnma.COM
- Organization: Fannie Mae
- References: <durai.107.726186277@ortta.umn.edu>
- Date: Tue, 5 Jan 1993 14:44:38 GMT
- Lines: 134
-
- In article 726186277@ortta.umn.edu, durai@ortta.umn.edu (Durai Venkatasubramanian) writes:
- >In article <1993Jan4.201319.9088@almserv.uucp> g9utxu@fnma.COM (Tanin Uthayanaka) writes:
-
- >I really appreciate the time and effort Tanin and Tom have taken to help me (
- >and others, probably) out. I am yet to translate(!) Tom's code to foxpro.
- >
- >Just to set the records straight, I would like to share the results of
- >running Tanin's code. No offence please. I am not here to point out bugs
- >or inefficient coding, but just to acknowledge the fact about how the code
- >works.
- >
- >Records in my rate.dbf
- >
- >Rate Start_date End_date Status
- >01 07/01/91 06/30/93 Provisional
- >02 07/01/92 06/30/93 Final
- >03 07/01/93 12/31/93 Provisional
- >
- >
- >Test data 1: dstart = 01/01/92, dend = 01/06/93
- >
- >Results: 01/01/92 - 12/31/93 Provisional
- > 01/01/94 - 01/06/93 Uncovered
- >
- >whereas, the results should have been
- > 01/01/92 - 06/30/92 Provisional
- > 07/01/92 - 01/06/93 Final
- >
-
- I must have misunderstood your requirement because my assumption was that there
- should not be an overlapping of periods in RATE.DBF. For example, record # 1 with
- 07/01/91 - 06/30/93 dates should have been 07/01/91 - 06/30/92 otherwise there is
- a conflict between 07/01/92 - 06/30/93 wether the status should be Provisional or
- Final. If the the dates in record # 1 were changed to 07/01/91 - 06/30/92 then the
- results would have been:
-
- 01/01/92 - 06/30/92 Provisional
- 07/01/92 - 01/06/93 Final
-
- I have tested the program already and I can guarantee that the program works. If
- you want a copy of the .EXE file just e-mail me and I'll send it to you.
-
-
-
- >Test data 2: dstart = 07/01/91, dend = 12/31/93
- >
- >Results: 07/01/91 - 06/03/93 Provisional
- > 07/01/92 - 06/30/93 Final
- > 07/01/93 - 12/31/93 Provisional
- > 01/01/94 - 12/31/93 Uncovered
- >
- >whereas, the last line should not have even appeared, forget the
- >error (12/31/93). I amended the code a little bit, and eliminated
- >the last line.
- >
- >The code works fine as long as the records in the database match the dstart
- >and dend variables. Most of the times, the contract periods either start
- >before, or end after, the rate agreement dates. These algorithms tend to
- >ignore the fact.
- >
-
- Congrads...you found the bug. For that you win $10,000,000. Just kidding.
- Since you found the bug I'll give you my final version which runs perfectly assuming
- there is no overlap of dates.
-
- CLEAR
- dStart:=dEnd:=CTOD(" / / ")
- @ 3,5 SAY "Starting Date: " GET dStart PICTURE "99/99/99"
- @ 4,5 SAY " Ending Date: " GET dEnd PICTURE "99/99/99"
- READ
-
- @ 10,10 SAY "Subcontract Period: "+DTOC(dStart)+" - "+DTOC(dEnd)
- @ 11,0 SAY ""
- USE RATE
- INDEX ON START_DATE TO START
- *** Soft seek in Clipper will search the next available record if there is no match
- SET SOFTSEEK ON
- SEEK dStart
- *** FOUND() statement can NOT be used because soft seek will always be .F. for FOUND()
- IF ! EOF()
- *** When you are at the next available record, you MUST skip back to check if the
- *** ending date in the RATE.DBF and compare it with the user's beginning date
- SKIP -1
- IF RATE->END_DATE >= dStart
- *** Since the ending date in RATE.DBF is greater then the contract status
- *** should be printed between the user's beginning and the RATE.DBF ending date
- @ ROW()+1,15 SAY DTOC(dStart)+" - "+DTOC(RATE->END_DATE)
- @ ROW(), 40 SAY RATE->STATUS
- ENDIF
- *** Now that you have checked if the above, you MUST return to the next available
- *** record
- SKIP +1
- *** You may now loop until the RATE.DBF starting date is greater than or equal to
- *** the user's starting date and compare the ending dates
- DO WHILE RATE->START_DATE >= dStart
- IF RATE->END_DATE <= dEnd
- @ ROW()+1,15 SAY DTOC(RATE->START_DATE)+" - "+DTOC(RATE->END_DATE)
- @ ROW(), 40 SAY RATE->STATUS
- ELSE
- @ ROW()+1,15 SAY DTOC(RATE->END_DATE+1)+" - "+DTOC(dEnd)
- @ ROW(), 40 SAY "Uncovered"
- EXIT
- ENDIF
- SKIP +1
- IF EOF()
- *** Eventhough you are at EOF(), you must skip back and check that the
- *** ending date is still within the range
- SKIP -1
- IF dEnd # RATE->END_DATE && Here was the bug
- @ ROW()+1,15 SAY DTOC(RATE->END_DATE+1)+" - "+DTOC(dEnd)
- @ ROW(), 40 SAY "Uncovered"
- ENDIF
- EXIT
- ENDIF
- ENDDO
- ELSE
- *** Again, eventhough you are at EOF(), you must skip back and check that the
- *** ending date is still within the range (i.e. RATE.DBF with one record)
- SKIP -1
- IF RATE->END_DATE >= dStart
- @ ROW()+1,15 SAY DTOC(dStart)+" - "+DTOC(RATE->END_DATE)
- @ ROW(), 40 SAY RATE->STATUS
- @ ROW()+1,15 SAY DTOC(RATE->END_DATE+1)+" - "+DTOC(dEnd)
- @ ROW(), 40 SAY "Uncovered"
- ELSE
- @ ROW()+1,15 SAY DTOC(dStart)+" - "+DTOC(dEnd)
- @ ROW(), 40 SAY "Uncovered"
- ENDIF
- ENDIF
- SET SOFTSEEK OFF
- SET INDEX TO
- USE
-
-
-