MonthView question

MiniMe
03-08-2004, 09:03 AM
Hiya,

I have a control array and above the control array, I have 7 labels, one for each day of the week. I've also got a DTPicker1 control which is selected by the user. Ignoring the commented bits of code, the code below produces the following:

'FindDate = Format(CurDate, "d", vbMonday) 'Find current Date
'FindWeekday = Format(CurDate, "w", vbMonday) 'Find day of week no. (1-7)
'FindMonday = FindDate - (FindWeekday - 1) 'Subtract to find Monday

For NoDays = 0 To 6
lblDay(NoDays) = Format(NoDays + 2, "dddd", vbMonday) + " " + Str$(frmEntry.DTPicker1 + NoDays) 'Puts day/date at top of each column
Next NoDays

Supposing the user selects the date: 18/02/04 the following is displayed.

Monday ; Tuesday ; Wednesday ; Thursday ; Friday ; Saturday ; Sunday
18/02/04; 19/02/04 ; 20/02/04 ; 21/02/04 ; 22/02/04 ; 23/02/04 ; 24/02/04

However, 18/02/04 is not a Monday and also when I click through the other MonthView dates, they same the same. Before implementing the DatePicker function I had the following and this worked fine. Is there any way to combine the two so that this works?

FindDate = Format(CurDate, "d", vbMonday) 'Find current Date
FindWeekday = Format(CurDate, "w", vbMonday) 'Find day of week no. (1-7)
FindMonday = FindDate - (FindWeekday - 1) 'Subtract to find Monday

For NoDays = 0 To 6
lblDay(NoDays) = Format(NoDays + 2, "dddd", vbMonday) + " " + Str$(FindMonday+ NoDays) 'Puts day/date at top of each column
Next NoDays

Thanks,

MiniMe

thingimijig
03-08-2004, 09:32 AM
to be honest, im a bit confused as to what you want.
as far as i can figure, correct me if im wrong, when i user selects a date from the datepicker you want to find the nearest monday in reverse and then put the dates in a label control array from that found monday, if so try this, if not please explain a bit more.

Private Sub DTPicker1_Change()
Dim i As Integer, x As Integer

For i = 0 To 6
If Weekday(DateAdd("d", -i, DTPicker1.Value)) = 2 Then
For x = Label1.LBound To Label1.UBound
Label1(x).Caption = DateAdd("d", x, DateAdd("d", -i, DTPicker1.Value))
Next x
Exit For
End If
Next i

End Sub


thingimijig.

MiniMe
03-08-2004, 09:57 AM
Hi!

Kind of, but I also wanted the day of the week to be displayed as well: Monday 18/02/04
Tuesday 18/02/04
etc

When I click on different dates using the MonthView, the dates in the labels do not change... but they changed before when I was using:

lblDay(NoDays) = Format(NoDays + 2, "dddd", vbMonday) + " " + Str$(frmEntry.DTPicker1 + NoDays) 'Puts day/date at top of each column

MiniMe

Mandelbrot
03-08-2004, 10:03 AM
Hi Mini,


This is code I have for a similar application in Access (but does roughly the same thing)...

Private Function SetCalendar(paramDate As Date) As Boolean
'Update the calendar display...

Dim lngDay As Long
Dim datFirstDay As Date

On Error GoTo SetCalendar_Error


'Set the month...
[CURMONTH].Caption = Format(paramDate, "mmmm")
[CURYEAR] = Year(paramDate)

'Workout the first sunday...
datFirstDay = LastSunday(DateSerial(Year(paramDate), Month(paramDate), 1))

'Update the display...
For lngDay = 0 To 41

With Me("DAY" & lngDay)
.Caption = Format(datFirstDay + lngDay, "d")
.Visible = (Format(datFirstDay + lngDay, "mmmm") = [CURMONTH].Caption)
.BackColor = (Not (datFirstDay + lngDay = datReturnDate) And colSYSButtonFace) Or _
(datFirstDay + lngDay = datReturnDate And colWhite)
.ForeColor = (colBlue And ((datFirstDay + lngDay) = Date))
End With

Next lngDay


SetCalendar_Error:
If Err.Number <> 0 Then MsgBox Err.Number & ": " & Err.Description, vbCritical, "SetCalendar"

End Function

The idea with this, though, is that the day names stay stable along the bottom of the form, and the other labels (i.e. the day numbers) change from month to month...


Paul.

thingimijig
03-08-2004, 10:10 AM
change a line to include the format function


Label1(x).Caption = Format(DateAdd("d", x, DateAdd("d", -i, DTPicker1.Value)), "dddd dd/mm/yyyy")


thingimijig.

MiniMe
03-08-2004, 10:20 AM
Heya!

Thanks for that, it works now! Cheers 4 ur suggestion as well MandelBrot :)

Only problem is that the labels aren't responding to the MonthView function when I click on a different date, any ideas?

MiniMe

thingimijig
03-08-2004, 10:26 AM
besides the datepicker doing its job, what is the monthview suppose to do ?

thingimijig.

MiniMe
03-08-2004, 10:54 AM
When u click on the different dates in the MonthView, the labels are supposed to change to the clicked date. Dont know if this makes sense.

I'l take another look at my code and see if I can make sense of it. Chrs for your help,

MiniMe

MiniMe
03-08-2004, 11:36 AM
Hi,

I've added a very much shortened version of my project which illustrates what I'm talking about more easily. If you have the time, then I would be very grateful if you could take a quick look. The code that I am focusing on is in frmMain and is highlighted. The code I am using at present along with your own submission is included.

You can either start a new game or load the previously saved one. If you start a new one, click on Load Teams and a list of teams will appear from which you can select. Drop and drag at least 5 teams to the new list box.

The DTPicker control is in frmEntry and it is set to 18/02/04 at the moment.

At present, using my code, if you click on different dates in the MonthView in frmMain, the labels at the top of the screen change.

When I substitute this section of code with your own '''''*commented out*''''', the labels do not respond to the MonthView control when a date is clicked.

I hope I have explained this clearly enough,

Thanks again,

MiniMe

MiniMe
03-08-2004, 02:28 PM
Opps, didn't mean to scare ne1 with the 2mb file! Theyre just pictures, I've taken em out!

MiniMe

MiniMe
03-08-2004, 06:56 PM
Woo! Not to worry now, done it! :D

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum