by Rick Lipkin » Mon Aug 27, 2007 4:34 pm
Devwin
Here is a snipit of code I user to create a database of calendar days for a vehicle reservation listbox grid .. Hope this give you an idea how to create a database on the fly with fields names that give you days of the week for columns.
Rick Lipkin
//
..................
DBF_STRU := { }
AADD( DBF_STRU, { "VNUMBER", "C", 5, 0 } )
AADD( DBF_STRU, { "LICENSE", "C", 7, 0 } )
AADD( DBF_STRU, { "MILEAGE", "N", 7, 0 } )
AADD( DBF_STRU, { "NEXTSERVCE", "D", 8, 0 } )
AADD( DBF_STRU, { "NEXTMILAGE", "N", 7, 0 } )
SELECT P_TRIPS
GO TOP
IF ( DATE() - P_TRIPS->DATE ) > 45
IF P_TRIPS->DATE = CTOD("00/00/00")
ELSE
SAYING := "There are Reservations over 45 days old that must be "+chr(10)
SAYING += "RESOLVED "+DTOC(P_TRIPS->DATE)+" "+P_TRIPS->VNUMBER+chr(10)
SAYING += " "+P_TRIPS->LNAME+chr(10)
MsgInfo( SAYING )
ENDIF
dDATE1 := DATE()-45
ELSE
dDATE1 := P_TRIPS->DATE
ENDIF
IF dDATE1 > DATE()
dDATE1 := DATE()
ENDIF
dDATE2 := DATE()+30
nSPREAD := ( dDATE2 - dDATE1 )
dTODAY := dDATE1
nCOL := 0
FOR i = 0 to nSPREAD
cDAY := substr( DOM(dTODAY),1,3)+"_" +;
substr( CMONTH(dTODAY),1,3)+"_"+;
strzero( DAY(dTODAY),2)
AADD( DBF_STRU, { cDAY, "C", 15, 0 } )
IF dTODAY = DATE()
IF i > 3
nCOL := (i+2)
ENDIF
ENDIF
dTODAY++
NEXT
DBCREATE( xVOL+"\DBTMP\"+SITEDBF+".DBF", DBF_STRU )
......
//-----------------------
Func DOM( dDATE)
LOCAL nDAY, cDAY
nDAY := DOW( dDATE )
DO CASE
CASE nDAY = 1
cDAY := "Sunday"
CASE nDAY = 2
cDAY := "Monday"
CASE nDAY = 3
cDAY := "Tuesday"
CASE nDAY = 4
cDAY := "Wednesday"
CASE nDAY = 5
cDAY := "Thursday"
CASE nDAY = 6
cDAY := "Friday"
CASE nDAY = 7
cDAY := "Saturday"
ENDCASE
RETURN(cDAY)