Subject: | Re: Help with writing tcursor
| Date: | Fri, 22 May 2020 23:12:00 +1000
| From: | Bernie van't Hof <onrequest@somewhere>
| Newsgroups: | pnews.paradox-programming
|
Once upon a time (PdoxDOS) I had similar issue. Here is the original PAL
code (stripped down a little) even with EDIT (ouch). This is from some
of the oldest PAL I ever wrote. Still working fine. Used regularly on
(unkeyed) table of 200K+ records. Seemed fast enough. Maybe I didn't
understand crosstabs back then.
Query
SrcTable | Date | Ref | Amt |
| CheckPlus | CheckPlus | CheckPlus |
Endquery
[SrcTable->Date] = period
Do_It!
RENAME "Answer" "Tmp"
CLEARALL
EDIT "Tmp"
Home
MOVETO [Date]
SCAN
IF NOT ISBLANK([Date]) THEN
[] = [] - DAY([]) + 1
[Amt] = ROUND([Amt], 2)
ENDIF
ENDSCAN
Do_It!
CLEARALL
Query
Tmp | Date | Amt | Src |
| Check | calc sum as amt | Check |
Endquery
Do_It!
CLEARALL
- Bernie
On 22/5/20 7:28 pm, Kevin Baker wrote:
> First, the code works for combining the data from CT2.db into CT1.db,
> but now I'm getting strange things happening when creating the CT2.db.
>
> The user selects the year they want (i.e. 2019) and I use the below code
> to generate CT2.DB (I also tried another method I'll discuss later in
> this post).
>
> ;build month begin/end vars
> s1 = "1/1/"+yv
> e1 = "1/31/"+yv
>
> s2 = "2/1/"+yv
> if s2.isLeapYear() then
> e2 = "2/29/"+yv
> else
> e2 = "2/28/"+yv
> endif
>
> s3 = "3/1/"+yv
> e3 = "3/31/"+yv
>
> s4 = "4/1/"+yv
> e4 = "4/30/"+yv
>
> s5 = "5/1/"+yv
> e5 = "5/31/"+yv
>
> s6 = "6/1/"+yv
> e6 = "6/30/"+yv
>
> s7 = "7/1/"+yv
> e7 = "7/31/"+yv
>
> s8 = "8/1/"+yv
> e8 = "8/31/"+yv
>
> s9 = "9/1/"+yv
> e9 = "9/30/"+yv
>
> s10 = "10/1/"+yv
> e10 = "10/31/"+yv
>
> s11 = "11/1/"+yv
> e11 = "11/30/"+yv
>
> s12 = "12/1/"+yv
> e12 = "12/31/"+yv
>
> qvar = query
> ANSWER: :PRIV:CT2.DB
>
> Giving.DB | MainId | Date | Amount
|
> Category |
> | Check not blank | >=~s1,<=~e1 | calc sum as Total,
> calc "Jan" as "Month" | check not split |
> | Check not blank | >=~s2,<=~e2 | calc sum as Total,
> calc "Feb" as "Month" | check not split |
> | Check not blank | >=~s3,<=~e3 | calc sum as Total,
> calc "Mar" as "Month" | check not split |
> | Check not blank | >=~s4,<=~e4 | calc sum as Total,
> calc "Apr" as "Month" | check not split |
> | Check not blank | >=~s5,<=~e5 | calc sum as Total,
> calc "May" as "Month" | check not split |
> | Check not blank | >=~s6,<=~e6 | calc sum as Total,
> calc "Jun" as "Month" | check not split |
> | Check not blank | >=~s7,<=~e7 | calc sum as Total,
> calc "Jul" as "Month" | check not split |
> | Check not blank | >=~s8,<=~e8 | calc sum as Total,
> calc "Aug" as "Month" | check not split |
> | Check not blank | >=~s9,<=~e9 | calc sum as Total,
> calc "Sep" as "Month" | check not split |
> | Check not blank | >=~s10,<=~e10 | calc sum as Total,
> calc "Oct" as "Month" | check not split |
> | Check not blank | >=~s11,<=~e11 | calc sum as Total,
> calc "Nov" as "Month" | check not split |
> | Check not blank | >=~s12,<=~e12 | calc sum as Total,
> calc "Dec" as "Month" | check not split |
> endQuery
>
> if not executeQBE(qvar) then
> errorShow()
> endif
>
>
> When this runs, I get errors like 1.jpg and 2.jpg. So I switch to
> creating CT2.db by creating a new CT3.db file as shown below:
>
> qvar = query
> ANSWER: :PRIV:CT3.DB
>
> Giving.DB | MainId | Date | Amount | Category |
> PmtMeth |
> | Check Not Blank | Check | Check | Check Not Split,
> Not Blank | calc blank as "Month" |
> endQuery
>
> if not executeQBE(qvar) then
> errorShow()
> endif
>
> ;Compute Month
> tc1.open(":PRIV:CT3.DB")
> tc1.edit()
>
> scan tc1:
> tc1."Month" = moy(tc1."Date")
> tc1.unlockRecord()
> endScan
>
> tc1.endEdit()
> tc1.close()
>
>
> When I run the tcursor, it updates the first record, then I get a GPV.
>
> I'm not sure if I'm doing something wrong or if this is come kind of bug
> in Paradox.
>
> I'm doing this as a DIY crosstab query.
>
> To help in reading the queries I've attached them as text files.
>
> Thanks
> Kevin
>
>
|