Mozkiller
12th July 2005, 21:46
Guys, please
I need to save a field that contains the days of the months, liked a calendar that changes conform the year and the month. For example, my form has a label with the week days and below that, has the days of that month chosen anteriorly, so these days have to change the positions on the form conform the week day that they are in that month. Somebody knows how can I do that???

mark_h
13th July 2005, 13:57
Is this based off of the company calendar? I take it you are talking about something like this:

Sun Mon Tue Wed Thu Fri Sat
xxx xxx xxx xxx xxx xxx xxx
xxx xxx xxx xxx xxx xxx xxx
xxx xxx xxx xxx xxx xxx xxx
xxx xxx xxx xxx xxx xxx xxx
xxx xxx xxx xxx xxx xxx xxx

And you just want to fill it in - correct? You can lookup sprintf and get which day of the week that a month starts. On some of my sessions where the user gives me a year and a month I use this to get the start date:

to.date = date.to.num(some.year,some.month,1)

Then you could use the company calendar to get the last day of the month. With this it would tell you which XXX to start on in the first week and how many boxes to fill in. Not sure if this is what you are looking for or if it is even close.

Mozkiller
13th July 2005, 23:07
Thanks mark_h!!! I´m gonna try to do this!!! :)

klixy23
14th July 2005, 11:46
Now here is an example code:


declaration:
extern domain tcdate day(42)
extern domain tcmcs.str20 month
extern domain tcmcs.str30 label

long weekday, week.line
long first.day, last.day
long y, m, d, w
long ret

|****************************** FIELD SECTION ***************************
field.month:
before.display:
| define the weekday label
label = "MONTUEWEDTHUFRISATSUN"

month = sprintf$("%D(%H)", date.num())
num.to.date(date.num(), y, m, d)
first.day = date.to.num(y, m, 1) | first day of month
last.day = date.to.num(y, m+1, 1)-1 | last day of month
w = lval(sprintf$("%D(%W)", first.day))

field.day:
before.display:
weekday = attr.element\7
week.line = attr.element/7
if weekday = 0 then
weekday = 7
week.line = week.line - 1
endif
ret = inputstr.to.date( sprintf$("%d%d%d", weekday, w + week.line, y), "%D017")

if ret >= first.day and ret <= last.day then
day(attr.element) = ret
else
day(attr.element) = 0
endif

| highlight the actual date
if ret = date.num() then
attr.cf = 4
else
attr.cf = 0
endif


The change of year isn't implemented yet.

The form is as followes:

month
label ... label
day(01) ... day(07)
day(08) ... day(14)
...
day(36) ... day(42)


The field label is repeated 7 times with the start pos incremented.
The day field has the format %D008 (day in month).

I hope this helps you and you can play around with.