home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
High Voltage Shareware
/
high1.zip
/
high1
/
DIR7
/
FOXTAILS.ZIP
/
GET_DATE.PRG
< prev
next >
Wrap
Text File
|
1992-03-28
|
5KB
|
133 lines
FUNCTION Get_Date
PARAMETER Dt
* Written by R.L. Coppedge
* Copyright 1992 dbF Software Productions
* By the way, dbF also has:
* SysTrak A Computer Hardware/Software Inventory System
* Flags A Flatfile Application Gen. for db3,4 and Fox
* ClasAdz A Classified/Notice system for Networks
* FerretPro A collection of FoxPro tools (like this one)
* Contact dbF for more information.
* dbF Software Productions
* P.O. Box 37194
* Cleve., Ohio 44137-0194
* CIS: 72117,165
* (216)491-4581
*
* This code may be modified, but leave this original notice up
* here intact, if ya don't mind. (Add your own comments about
* how much better you made it if you like)
* What this function does is display a calendar format so that
* the user can grab a date. It isn't a VALIDation, per se, but
* an entry piece. See the sample code (SAMPLE, which wins the
* Irving Forbush Original Program Name of the Year Award) for
* an example of how this would all work.
Tk = SET("Talk")
M = CMONTH(Dt)
Y = YEAR(Dt)
DEFINE WINDOW Get_Date FROM 2,5 TO 19,50 DOUBLE TITLE "Get A Date"
ACTIVATE WINDOW Get_Date
* 1st we place the skeleton onto the window
@ 0,0 SAY "│" + SPACE(20) + "│"
@ 1,0 SAY "│Su Mo Tu We Th Fr Sa│"
@ 2,0 SAY "├──┬──┬──┬──┬──┬──┬──┤"
@ 3,0 SAY "│ │ │ │ │ │ │ │"
@ 4,0 SAY "├──┼──┼──┼──┼──┼──┼──┤"
@ 5,0 SAY "│ │ │ │ │ │ │ │"
@ 6,0 SAY "├──┼──┼──┼──┼──┼──┼──┤"
@ 7,0 SAY "│ │ │ │ │ │ │ │"
@ 8,0 SAY "├──┼──┼──┼──┼──┼──┼──┤"
@ 9,0 SAY "│ │ │ │ │ │ │ │"
@10,0 SAY "├──┼──┼──┼──┼──┼──┼──┤"
@11,0 SAY "│ │ │ │ │ │ │ │"
@12,0 SAY "├──┼──┼──┼──┼──┼──┼──┤"
@13,0 SAY "│ │ │ │ │ │ │ │"
@14,0 SAY "└──┴──┴──┴──┴──┴──┴──┘"
D = Dt
Butn = 0
Cntr = 0
DO WHILE .T.
* Now we place the title line for month and date
Tstr = CMONTH(D) + " "+STR(YEAR(D),4)
Tstr = IIF(LEN(Tstr)/2=INT(LEN(Tstr)/2),Tstr,Tstr+" ")
Ln1 = "│"+SPACE((20-LEN(Tstr))/2) + Tstr +SPACE((20-LEN(Tstr))/2) +"│"
@0,0 SAY Ln1
* Now we figure out how many days there are...
Dys = IIF(INLIST(MONTH(D),4,6,9,11),30,31)
IF MONTH(D) = 2 && Oh, yeah...February
Dys = IIF(YEAR(D)/4=INT(YEAR(D)/4) AND YEAR(D)/1000 <> INT(YEAR(D)/1000) ,29,28)
ENDIF
* Now, let's place the numbers in their respective spots
Bd = D-DAY(D)+1
FOR X = 1 TO 42 && There're 42 spaces (7 columns, 6 Rows)
Shw= IIF(X < DOW(Bd) OR X>=Dys+DOW(Bd)," ",STR(X-DOW(Bd)+1,2,0))
@3+INT((X-1)/7)*2, 3*((X-1)-INT((X-1)/7)*7)+1 SAY Shw
ENDFOR
* This is kinda tricky...basically the whole thing is 6 Invisible
* Box GETs with many of the beginning and ending week disabled,
* depending on the day of the week that the month begins
* So we have to create for week 1,5,6 the proper PICTURE.
W1pic = "@*IHT " + REPLICATE(";",7-(DOW(Bd)-1)-1)
W5num = IIF(Dys-(21+7-(DOW(Bd)-1))>7,7,Dys-(21+7-(DOW(Bd)-1)))
W5pic = "@*IHT " + REPLICATE(";",W5num-1)
W6num = Dys-(28+7-(DOW(Bd)-1))
W6pic = IIF(W6num>0,"@*IHT " + REPLICATE(";",W6num-1),"")
FOR Nn = 1 TO DAY(Dt) - 1
KEYBOARD "{RIGHTARROW}"
ENDFOR
@3,1+3*(DOW(Bd)-1) GET W1 PICTURE W1pic SIZE 1,2,1 DEFAULT 1 VALID Chk("1")
* Notice that Week # 2,3,4 are ALWAYS the same.
@5,1 GET W2 PICTURE "@*IHT ;;;;;;" SIZE 1,2,1 DEFAULT 1 VALID Chk("2")
@7,1 GET W3 PICTURE "@*IHT ;;;;;;" SIZE 1,2,1 DEFAULT 1 VALID Chk("3")
@9,1 GET W4 PICTURE "@*IHT ;;;;;;" SIZE 1,2,1 DEFAULT 1 VALID Chk("4")
@11,1 GET W5 PICTURE W5pic SIZE 1,2,1 DEFAULT 1 VALID Chk("5")
IF !EMPTY(W6pic)
@13,1 GET W6 PICTURE W6pic SIZE 1,2,1 DEFAULT 1 VALID Chk("6")
ENDIF
* Or the user may want to move by month or year.
MvPic = "@*VT -M;+M;-Y;+Y;Today;"+DTOC(Dt)
@3,28 GET Mv PICTURE Mvpic DEFAULT 1 VALID Chk("M")
READ CYCLE
IF LASTKEY() = 27 && They hit escape...adios!
RELEASE WINDOW Get_Date
IF Tk = "ON"
SET TALK ON
ENDIF
RETURN Dt && Return original value.
ENDIF
IF Butn = 0 && They didn't hit a date number!
DO CASE
CASE Mv = 1 && Back one month
D = GOMONTH(D,-1)
CASE Mv = 2 && Forward one month
D = GOMONTH(D,1)
CASE Mv = 3 && Back one year
D = GOMONTH(D,-12)
CASE Mv = 4 && Forward one year
D = GOMONTH(D,12)
CASE Mv = 5 && go to today's date
D = DATE()
CASE Mv = 6 && Reset to Original Date
D = Dt
ENDCASE
LOOP
ENDIF
IF Butn = 1 && They hit during the 1st week...
Andy = STR(W1,2)
ELSE
Andy = STR((Butn-1)*7 + EVALUATE("W"+STR(Butn,1)) - DOW(Bd)+1,2)
ENDIF
Ans = CTOD(STR(MONTH(D),2)+"/" +Andy + "/"+STR(YEAR(D),4))
RELEASE WINDOW Get_Date
IF Tk = "ON"
SET TALK ON
ENDIF
RETURN Ans
ENDDO
PROCEDURE Chk
PARAMETER What && We need this to tell which row they hit.
Butn = VAL(What)
RETURN .T.