 |

03-08-2004, 09:03 AM
|
|
Centurion
|
|
Join Date: Dec 2003
Location: England, Loughborough
Posts: 173
|
|
MonthView question
|
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:
Code:
'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?
Code:
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
|
__________________
Nothing is impossible...
Last edited by herilane; 03-08-2004 at 03:27 PM.
Reason: fixed [code] tags
|

03-08-2004, 09:32 AM
|
|
Senior Contributor
* Expert *
|
|
Join Date: Jul 2003
Posts: 1,300
|
|
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.
Code:
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.
|
|

03-08-2004, 09:57 AM
|
|
Centurion
|
|
Join Date: Dec 2003
Location: England, Loughborough
Posts: 173
|
|
|
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
|
__________________
Nothing is impossible...
|

03-08-2004, 10:03 AM
|
 |
Senior Contributor
|
|
Join Date: Apr 2002
Location: glbTheWorld.Europe.UK
Posts: 1,201
|
|
Hi Mini,
This is code I have for a similar application in Access (but does roughly the same thing)...
Code:
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.
|
|

03-08-2004, 10:10 AM
|
|
Senior Contributor
* Expert *
|
|
Join Date: Jul 2003
Posts: 1,300
|
|
change a line to include the format function
Code:
Label1(x).Caption = Format(DateAdd("d", x, DateAdd("d", -i, DTPicker1.Value)), "dddd dd/mm/yyyy")
thingimijig.
|
|

03-08-2004, 10:20 AM
|
|
Centurion
|
|
Join Date: Dec 2003
Location: England, Loughborough
Posts: 173
|
|
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
|
__________________
Nothing is impossible...
|

03-08-2004, 10:26 AM
|
|
Senior Contributor
* Expert *
|
|
Join Date: Jul 2003
Posts: 1,300
|
|
|
besides the datepicker doing its job, what is the monthview suppose to do ?
thingimijig.
|
|

03-08-2004, 10:54 AM
|
|
Centurion
|
|
Join Date: Dec 2003
Location: England, Loughborough
Posts: 173
|
|
|
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
|
__________________
Nothing is impossible...
|

03-08-2004, 11:36 AM
|
|
Centurion
|
|
Join Date: Dec 2003
Location: England, Loughborough
Posts: 173
|
|
|
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
|
__________________
Nothing is impossible...
|

03-08-2004, 02:28 PM
|
|
Centurion
|
|
Join Date: Dec 2003
Location: England, Loughborough
Posts: 173
|
|
|
Opps, didn't mean to scare ne1 with the 2mb file! Theyre just pictures, I've taken em out!
MiniMe
|
__________________
Nothing is impossible...
|

03-08-2004, 06:56 PM
|
|
Centurion
|
|
Join Date: Dec 2003
Location: England, Loughborough
Posts: 173
|
|
Woo! Not to worry now, done it! 
|
__________________
Nothing is impossible...
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|