Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > MonthView question


Reply
 
Thread Tools Display Modes
  #1  
Old 03-08-2004, 09:03 AM
MiniMe MiniMe is offline
Centurion
 
Join Date: Dec 2003
Location: England, Loughborough
Posts: 173
Default 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
Reply With Quote
  #2  
Old 03-08-2004, 09:32 AM
thingimijig thingimijig is offline
Senior Contributor

* Expert *
 
Join Date: Jul 2003
Posts: 1,300
Default

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.
Reply With Quote
  #3  
Old 03-08-2004, 09:57 AM
MiniMe MiniMe is offline
Centurion
 
Join Date: Dec 2003
Location: England, Loughborough
Posts: 173
Default

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...
Reply With Quote
  #4  
Old 03-08-2004, 10:03 AM
Mandelbrot's Avatar
Mandelbrot Mandelbrot is offline
Senior Contributor
 
Join Date: Apr 2002
Location: glbTheWorld.Europe.UK
Posts: 1,201
Default

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.
Reply With Quote
  #5  
Old 03-08-2004, 10:10 AM
thingimijig thingimijig is offline
Senior Contributor

* Expert *
 
Join Date: Jul 2003
Posts: 1,300
Default

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.
Reply With Quote
  #6  
Old 03-08-2004, 10:20 AM
MiniMe MiniMe is offline
Centurion
 
Join Date: Dec 2003
Location: England, Loughborough
Posts: 173
Default

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...
Reply With Quote
  #7  
Old 03-08-2004, 10:26 AM
thingimijig thingimijig is offline
Senior Contributor

* Expert *
 
Join Date: Jul 2003
Posts: 1,300
Default

besides the datepicker doing its job, what is the monthview suppose to do ?

thingimijig.
Reply With Quote
  #8  
Old 03-08-2004, 10:54 AM
MiniMe MiniMe is offline
Centurion
 
Join Date: Dec 2003
Location: England, Loughborough
Posts: 173
Default

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...
Reply With Quote
  #9  
Old 03-08-2004, 11:36 AM
MiniMe MiniMe is offline
Centurion
 
Join Date: Dec 2003
Location: England, Loughborough
Posts: 173
Default

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
Attached Files
File Type: zip MyProj.zip (1.99 MB, 6 views)
__________________
Nothing is impossible...
Reply With Quote
  #10  
Old 03-08-2004, 02:28 PM
MiniMe MiniMe is offline
Centurion
 
Join Date: Dec 2003
Location: England, Loughborough
Posts: 173
Default

Opps, didn't mean to scare ne1 with the 2mb file! Theyre just pictures, I've taken em out!

MiniMe
Attached Files
File Type: zip MyProj.zip (18.4 KB, 3 views)
__________________
Nothing is impossible...
Reply With Quote
  #11  
Old 03-08-2004, 06:56 PM
MiniMe MiniMe is offline
Centurion
 
Join Date: Dec 2003
Location: England, Loughborough
Posts: 173
Default

Woo! Not to worry now, done it!
__________________
Nothing is impossible...
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Easy Question..... KnooKie General 4 05-23-2003 03:45 AM
Question on Timers Zetsubo General 2 04-20-2003 03:12 PM
Date format question with Calendar Control jennie_1951 General 2 04-17-2003 07:08 PM
OS Question project 32 Tech Discussions 9 10-15-2001 09:23 AM
Back button zukester General 31 08-15-2001 12:05 PM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->