home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Best Objectech Shareware Selections
/
UNTITLED.iso
/
boss
/
data
/
dbas
/
004
/
sca.prg
< prev
next >
Wrap
Text File
|
1992-09-09
|
16KB
|
404 lines
*-------------------------------------------------------------------------------
*-- Program...: SCA.PRG
*-- Programmer: Ken Mayer (KENMAYER)
*-- Date......: 06/25/1992
*-- Notes.....: This file contains the SCA Date handling routines, as well as a
*-- copy of the roman numeral to arabic and vice-versa functions,
*-- that are contained in CONVERT.PRG. This is due to the fact
*-- that only two library files may be open at one time. See
*-- the file README.TXT for more details on the use of this library
*-- file.
*-------------------------------------------------------------------------------
PROCEDURE SCA_Real
*-------------------------------------------------------------------------------
*-- Programmer..: Ken Mayer (Hirsch von Henford in the SCA) (KENMAYER)
*-- Date........: 07/29/1991
*-- Notes.......: This procedure was designed to handle data entered into
*-- the Order of Precedence of the Principality of the Mists.
*-- The problem is, my usual sources of data give only SCA
*-- dates, and in order to sort properly, I need real dates.
*-- This procedure will handle it, and goes hand-in-hand with
*-- the function Real_SCA, to translate real dates to SCA
*-- dates ... This procedure assumes that you have set the
*-- F1 Key (see Example below). If you use a different F key,
*-- you will want to modify the ON KEY LABEL commands ...
*-- Written for.: dBASE IV, 1.1
*-- Rev. History: 07/23/1991 - original procedure.
*-- 07/29/1991 -- modified it to stuff a character directly into
*-- a date field (was having to do a CTOD in the program),
*-- and added use of ESC to escape out, instead of killing
*-- the procedure and the program calling it ...
*-- Calls.......: CENTER Procedure in PROC.PRG
*-- SHADOW Procedure in PROC.PRG
*-- ARABIC() Function in PROC.PRG
*-- Called by...: Any
*-- Usage.......: do SCA_Real
*-- Example.....: on key label f1 do sca_real
*-- store {} to t_date && initialize as a date
*-- && or you could STORE datefield to t_date
*-- && if you have a date field ...
*-- clear
*-- @5,10 say "Enter a date:" get t_date;
*-- message "Press <F1> to convert from SCA date to real date"
*-- read
*-- on key label f1 && clear out that command ...
*-- Returns.....: real date, forced into field ...
*-- Parameters..: None
*-------------------------------------------------------------------------------
private cEscape,cExact,cYear,cMonth,cDay,nYearlen,nCount,nYear,nMonth
private nDay,cDate
cEscape = set("ESCAPE")
set escape off && so we can handle the Escape Key
cExact = set("EXACT")
set exact on && VERY important ...
on key label F1 ?? chr(7) && make it beep, rather than call this procedure
&& again, which causes wierdnesses ...
*-- first let's popup a window to ask for the information ...
save screen to sDate
activate screen
define window wDate from 8,20 to 15,60 color rg+/gb,n/g,rg+/gb
do shadow with 8,20,15,60
activate window wDate
*-- set the memvars ...
cYear = space(8)
cMonth = space(3)
cDay = space(2)
do center with 0,40,"","Enter SCA Date below:"
do while .t.
@2,14 say "Month: " get cMonth ;
picture "@M JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC";
message "Enter first letter of month, <Space> to scroll through, "+;
"<Enter> to choose" color rg+/gb,n/g
@3,14 say " Day: " get cDay picture "99";
message "Enter 2 digits for day of the month, if blank will assume 15";
color rg+/gb,n/g
@4,14 say " Year: " get cYear picture "!!!!!!!!" ;
message "Enter year in AS roman numeral format";
valid required len(trim(cYear)) > 0;
error chr(7)+"This is no good without a year ..." color rg+/gb,n/g
read
if lastkey() = 27 && if user wants out by pressing <Esc>
deactivate window wDate
release window wDate
restore screen from sDate
release screen sDate
set escape &cEscape
set exact &cExact
on key label F1 do SCA_Real && reset it ...
return
endif
if lastkey() < 0 && function key F1 through Shift F9 was pressed
?? chr(7) && beep at user
loop && don't let 'em get away with that -- try again
endif
*-- check for valid roman numerals
cYear = trim(cYear) && trim it
nYearLen = len(cYear) && get length
nCount = 0
do while nCount < nYearLen && loop through length of year
nCount = nCount + 1 && increment
if .not. substr(cYear,nCount,1) $ "IVXLC" && if it's not here
do center with 5,40,"rg+/r","** ERROR -- Invalid Year **"
lError = .t. && set error flag
exit && exit internal loop
else
lError = .f. && make sure this is false
endif
enddo && end of internal loop
if lError && if error,
loop && go back ...
endif
@5,0 clear && clear out any error message ...
do center with 5,40,"rg+/r","Converting Date ..."
*-- First (and most important) is conversion of the year
nYear = Arabic(cYear)
*-- AS Years start at May ... if the month for a specific year is
*-- Jan through April it's part of the next "real" year ...
if cMonth = "JAN" .or. cMonth = "FEB" .or. cMonth = "MAR" .or.;
cMonth = "APR"
nYear = nYear + 1
endif
nYear = nYear + 65 && SCA dates start at 66 ...
if nYear > 99 && this thing doesn't handle turn of the century
@5,0 clear
do center with 5,40,"rg+/r","No dates past XXXIV, please"
loop
endif
*-- set numeric value of month ...
do case
case cMonth = "JAN"
nMonth = 1
case cMonth = "FEB"
nMonth = 2
case cMonth = "MAR"
nMonth = 3
case cMonth = "APR"
nMonth = 4
case cMonth = "MAY"
nMonth = 5
case cMonth = "JUN"
nMonth = 6
case cMonth = "JUL"
nMonth = 7
case cMonth = "AUG"
nMonth = 8
case cMonth = "SEP"
nMonth = 9
case cMonth = "OCT"
nMonth = 10
case cMonth = "NOV"
nMonth = 11
case cMonth = "DEC"
nMonth = 12
endcase
*-- if the day field is empty, assume the middle of the month, so we
*-- have SOMETHING to go by ...
if len(alltrim(cDay)) = 0
nDay = 15
else
nDay = val(cDay)
endif
*-- Check for valid day of the month ...
if nDay > 29 .and. nMonth = 2 .or. (nDay = 31 .and. (nMonth = 4 .or.;
nMonth = 6 .or. nMonth = 9 .or. nMonth = 11))
do center with 5,40,"rg+/r",chr(7)+"INVALID DATE -- Try again ..."
loop
endif
exit && out of loop -- if here, we're done
enddo && end of loop
*-- Convert it
cDate = transform(nMonth,"@L 99")+transform(nDay,"@L 99")+;
transform(nYear,"@L 99")
*-- force this 'character' date into the date field on the screen ...
keyboard cDate clear && put it into the field, and clear out
&& keyboard buffer first ...
*-- deal with cleanup ...
deac wind wDate
release wind wDate
restore screen from sDate
release screen sDate
set escape &cEscape
set exact &cExact
on key label F1 do SCA_Real && reset for user
RETURN
*-- EoP: SCA_Real
FUNCTION SCA2Real
*-------------------------------------------------------------------------------
*-- Programmer..: Jay Parsons (JPARSONS)
*-- Date........: 04/22/1992
*-- Notes.......: Jay figured out a short version of SCA_Real above, which
*-- does not use screen input/screen display. This can be used
*-- directly as a function.
*-- Written for.: dBASE IV, 1.5
*-- Rev. History: None
*-- Calls.......: ALLTRIM()