473,549 Members | 2,584 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

MonthCalendar

I have a monthCalender that I want users to be able to
select a range of dates (or a single date) then calculate
a value based on the number of days that person has
selected. The values are higher for the weekends so I
need to be able to figure out how many of the selected
days are weekdays versus weekends.

I already have code to tell me the number of days the
person has selected. I also understand how to get the
DayOfWeek. I tried to code an nested if statement that
would check the dayofweek, see how far away from the
weekend it is and then check that against the number of
days the user selected but it has become unwieldly and,
well, pretty crazy looking.

I'm hoping that someone can tell me a simpler coding
method. My other thought was maybe it's possible
something to do with the SelectedRange? I thought maybe
there is a way to loop through selected range to see if
dayofweek for each weekend day fell inside that range but
I really don't know how I would do that (if it's even
possible)especi ally since dayofweek gives an integer while
selectedrange gives dates.

Oy!

Any help would be greatly appreciated.

Thank you.
Nov 20 '05 #1
13 3520
Cor
Hi Sand,

If you want us to help you to make your code more simple, than I think we
first have to see that.

Just a thought,

Cor
I have a monthCalender that I want users to be able to
select a range of dates (or a single date) then calculate
a value based on the number of days that person has
selected. The values are higher for the weekends so I
need to be able to figure out how many of the selected
days are weekdays versus weekends.

I already have code to tell me the number of days the
person has selected. I also understand how to get the
DayOfWeek. I tried to code an nested if statement that
would check the dayofweek, see how far away from the
weekend it is and then check that against the number of
days the user selected but it has become unwieldly and,
well, pretty crazy looking.

I'm hoping that someone can tell me a simpler coding
method. My other thought was maybe it's possible
something to do with the SelectedRange? I thought maybe
there is a way to loop through selected range to see if
dayofweek for each weekend day fell inside that range but
I really don't know how I would do that (if it's even
possible)especi ally since dayofweek gives an integer while
selectedrange gives dates.

Nov 20 '05 #2
* "Sand" <an*******@disc ussions.microso ft.com> scripsit:
I have a monthCalender that I want users to be able to
select a range of dates (or a single date) then calculate
a value based on the number of days that person has
selected. The values are higher for the weekends so I
need to be able to figure out how many of the selected
days are weekdays versus weekends.

I already have code to tell me the number of days the
person has selected. I also understand how to get the
DayOfWeek. I tried to code an nested if statement that
would check the dayofweek, see how far away from the
weekend it is and then check that against the number of
days the user selected but it has become unwieldly and,
well, pretty crazy looking.

I'm hoping that someone can tell me a simpler coding
method. My other thought was maybe it's possible
something to do with the SelectedRange? I thought maybe
there is a way to loop through selected range to see if
dayofweek for each weekend day fell inside that range but
I really don't know how I would do that (if it's even
possible)especi ally since dayofweek gives an integer while
selectedrange gives dates.


Post code!

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #3
Hi Sand,

First, set up 2 monthcalendar controls - start and end. Then have the user
select the same date in both if only one day. Then have a look at the
datediff function to determine the date range.

HTH,

Bernie Yaeger

"Sand" <an*******@disc ussions.microso ft.com> wrote in message
news:06******** *************** *****@phx.gbl.. .
I have a monthCalender that I want users to be able to
select a range of dates (or a single date) then calculate
a value based on the number of days that person has
selected. The values are higher for the weekends so I
need to be able to figure out how many of the selected
days are weekdays versus weekends.

I already have code to tell me the number of days the
person has selected. I also understand how to get the
DayOfWeek. I tried to code an nested if statement that
would check the dayofweek, see how far away from the
weekend it is and then check that against the number of
days the user selected but it has become unwieldly and,
well, pretty crazy looking.

I'm hoping that someone can tell me a simpler coding
method. My other thought was maybe it's possible
something to do with the SelectedRange? I thought maybe
there is a way to loop through selected range to see if
dayofweek for each weekend day fell inside that range but
I really don't know how I would do that (if it's even
possible)especi ally since dayofweek gives an integer while
selectedrange gives dates.

Oy!

Any help would be greatly appreciated.

Thank you.

Nov 20 '05 #4
I posted my original question after midnight, I was pretty
frazzled by that time. I think I can state the problem
more clearly now.

I have two variable dates. Projectstart and ProjectEnd I
also have two integers projectstart.da y and projectend.day
that correspond to those dates. I want to find out
whether either of two weekend days fall in between them.
Both weekend days have a reacurring integer value based on
the week (5 and 6 because my weekends are actually friday
and saturday) though I am unsure how to refer to them in
code.
I don't have much code now, I deleted my nested if
statements when I realized it was going to be unworkable.
The idea is simple enough though I can recreate it.

Rough code:

Dim intNumberOfDays as integer
Dim intNumberOfWeek days as integer
Dim intNumberOfWeek EndDays as integer

Private Sub MonthCalendar1_ DateChanged(byV al...) Handles
dtmCharges.Date Changed

'Find the number of days the user selected
intNumberOfDays = projectEnd.day - projectStart.da y

btnCalculateVal ue_click (byVal...) Handles
btnCalculateVal ue.Click

'Checking position of the project start day
'Calculate how many weekend versus weekdays based on how
'far away the start day is from the first weekend day
'then checking the total number of days selected to
'determine if it includes weekends
If projectStart.da yOfWeek = 1 and intNumberOfDays = 4 then
intNumberOfWeek Days = 3
intnumberOfWeek EndDDays = 1
else If projectStart.da yOfWeek = 1 and intNumberOfDays = 5
then
intNumberOfWeek Days = 3
intNumberOfWeek EndDays = 3
else if projectStart.da yOfWeek = 1 and intNumberofDays <=3
then
intnumberofWeek days = intNumberOfDays
intnumberofWeek EndDays = 0
else if projectStart.da yOfWeek = 1 and intNumberOfDays >=6
intnumberOfWeek Days = intNumberOfDays - 2
intNumberOfWeek EndDays = 2
end if
end if
end if

end sub
end class
As you can probabaly tell Id basically have to do the same
code checking to see if the projectstart.da y was 1-7
adjusting the numerical values if the day started
Monday,Tuesday, Wednesday,Thurs day,Friday,Satu rday or
Sunday and comparing it to the length of stay.

I hope that makes more sense then my original post.

thank you,

Sand
-----Original Message-----
* "Sand" <an*******@disc ussions.microso ft.com> scripsit:
I have a monthCalender that I want users to be able to
select a range of dates (or a single date) then calculate a value based on the number of days that person has
selected. The values are higher for the weekends so I
need to be able to figure out how many of the selected
days are weekdays versus weekends.

I already have code to tell me the number of days the
person has selected. I also understand how to get the
DayOfWeek. I tried to code an nested if statement that
would check the dayofweek, see how far away from the
weekend it is and then check that against the number of
days the user selected but it has become unwieldly and,
well, pretty crazy looking.

I'm hoping that someone can tell me a simpler coding
method. My other thought was maybe it's possible
something to do with the SelectedRange? I thought maybe
there is a way to loop through selected range to see if
dayofweek for each weekend day fell inside that range but I really don't know how I would do that (if it's even
possible)especi ally since dayofweek gives an integer while selectedrange gives dates.


Post code!

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
.

Nov 20 '05 #5
Hi Cor, good pont, please see my reply to Herfried.

Thank you,
Sand
-----Original Message-----
Hi Sand,

If you want us to help you to make your code more simple, than I think wefirst have to see that.

Just a thought,

Cor
I have a monthCalender that I want users to be able to
select a range of dates (or a single date) then calculate a value based on the number of days that person has
selected. The values are higher for the weekends so I
need to be able to figure out how many of the selected
days are weekdays versus weekends.

I already have code to tell me the number of days the
person has selected. I also understand how to get the
DayOfWeek. I tried to code an nested if statement that
would check the dayofweek, see how far away from the
weekend it is and then check that against the number of
days the user selected but it has become unwieldly and,
well, pretty crazy looking.

I'm hoping that someone can tell me a simpler coding
method. My other thought was maybe it's possible
something to do with the SelectedRange? I thought maybe
there is a way to loop through selected range to see if
dayofweek for each weekend day fell inside that range but I really don't know how I would do that (if it's even
possible)especi ally since dayofweek gives an integer while selectedrange gives dates.

.

Nov 20 '05 #6
Hi Bernie,

I'm a bit confused. As far as I can tell

Date diff returns a Long value specifying the number of
time intervals between two Date values.

DateDiff(interv al, date1 as object, date2 as object)

So if this is going to return the number of intervals
between two dates then that is no problem. The calendar
control has the ability to ive an integer value using .day
that I can then use to calculate the number of days
selected.

To get that I use

intNumberofDays Selected = projectend.day - projectStart.da y

I just tried to use the datediff function but because the
arguments Date1 and Date2 are objects not dates I'm
throwing exceptions. Maybe I could convert projectstart
and projectend to objects somehow? Even so if datediff is
just returning the number of intervals (in this case 1 day)
then my code already does that.

What I need is to check between thsoe dates to see if they
contain one or two weekend dates.

Thank you,
Sand
-----Original Message-----
Hi Sand,

First, set up 2 monthcalendar controls - start and end. Then have the userselect the same date in both if only one day. Then have a look at thedatediff function to determine the date range.

HTH,

Bernie Yaeger

"Sand" <an*******@disc ussions.microso ft.com> wrote in messagenews:06******* *************** ******@phx.gbl. ..
I have a monthCalender that I want users to be able to
select a range of dates (or a single date) then calculate a value based on the number of days that person has
selected. The values are higher for the weekends so I
need to be able to figure out how many of the selected
days are weekdays versus weekends.

I already have code to tell me the number of days the
person has selected. I also understand how to get the
DayOfWeek. I tried to code an nested if statement that
would check the dayofweek, see how far away from the
weekend it is and then check that against the number of
days the user selected but it has become unwieldly and,
well, pretty crazy looking.

I'm hoping that someone can tell me a simpler coding
method. My other thought was maybe it's possible
something to do with the SelectedRange? I thought maybe
there is a way to loop through selected range to see if
dayofweek for each weekend day fell inside that range but I really don't know how I would do that (if it's even
possible)especi ally since dayofweek gives an integer while selectedrange gives dates.

Oy!

Any help would be greatly appreciated.

Thank you.

.

Nov 20 '05 #7
Hi Sand,

DateDiff will return the difference between d1 and d2, as you are aware.
Convert your objects to date variables and you will have the range. The you
can use dateinterval.we ekday inside datediff to get the number of weekdays.
Then compare # of weekdays to the prior range total and if there's a 2 day
or more difference, you have your answer.

HTH,

Bernie

<an*******@disc ussions.microso ft.com> wrote in message
news:00******** *************** *****@phx.gbl.. .
Hi Bernie,

I'm a bit confused. As far as I can tell

Date diff returns a Long value specifying the number of
time intervals between two Date values.

DateDiff(interv al, date1 as object, date2 as object)

So if this is going to return the number of intervals
between two dates then that is no problem. The calendar
control has the ability to ive an integer value using .day
that I can then use to calculate the number of days
selected.

To get that I use

intNumberofDays Selected = projectend.day - projectStart.da y

I just tried to use the datediff function but because the
arguments Date1 and Date2 are objects not dates I'm
throwing exceptions. Maybe I could convert projectstart
and projectend to objects somehow? Even so if datediff is
just returning the number of intervals (in this case 1 day)
then my code already does that.

What I need is to check between thsoe dates to see if they
contain one or two weekend dates.

Thank you,
Sand
-----Original Message-----
Hi Sand,

First, set up 2 monthcalendar controls - start and end.

Then have the user
select the same date in both if only one day. Then have

a look at the
datediff function to determine the date range.

HTH,

Bernie Yaeger

"Sand" <an*******@disc ussions.microso ft.com> wrote in

message
news:06******* *************** ******@phx.gbl. ..
I have a monthCalender that I want users to be able to
select a range of dates (or a single date) then calculate a value based on the number of days that person has
selected. The values are higher for the weekends so I
need to be able to figure out how many of the selected
days are weekdays versus weekends.

I already have code to tell me the number of days the
person has selected. I also understand how to get the
DayOfWeek. I tried to code an nested if statement that
would check the dayofweek, see how far away from the
weekend it is and then check that against the number of
days the user selected but it has become unwieldly and,
well, pretty crazy looking.

I'm hoping that someone can tell me a simpler coding
method. My other thought was maybe it's possible
something to do with the SelectedRange? I thought maybe
there is a way to loop through selected range to see if
dayofweek for each weekend day fell inside that range but I really don't know how I would do that (if it's even
possible)especi ally since dayofweek gives an integer while selectedrange gives dates.

Oy!

Any help would be greatly appreciated.

Thank you.

.

Nov 20 '05 #8
Well I was looking at that code I posted and I realized it
would be better to do it, make sure it works and then post
it. I'm not sure how to make code look like it does
inside.net so I'll try to make it close

Here is the code, jsut checking if the starting date is
monday. I'd have to write the same code for tuesday-
sunday adjusting the values as I went.

Private Sub Button1_Click(B yVal sender As System.Object,
ByVal e As System.EventArg s) Handles Button1.Click

If projectStart.Da yOfWeek = 1 And intDaysStayed <= 3 Then
intWeekDay = intDaysStayed
intWeekend = 0
ElseIf projectStart.Da yOfWeek = 1 And intDaysStayed = 4
Then
intWeekDay = 3
intWeekend = 1
ElseIf projectStart.Da yOfWeek = 1 And intDaysStayed = 5
Then
intWeekDay = 3
intWeekend = 2
ElseIf projectStart.Da yOfWeek = 1 And intDaysStayed <= 10
Then
intWeekDay = intDaysStayed - 2
intWeekend = 2
ElseIf projectStart.Da yOfWeek = 1 And intDaysStayed = 11
Then
intWeekDay = intDaysStayed - 3
intWeekend = 3
ElseIf projectStart.Da yOfWeek = 1 And intDaysStayed = 12
Then
intWeekDay = intDaysStayed - 4
intWeekend = 4
ElseIf projectStart.Da yOfWeek = 1 And intDaysStayed >= 13
Then
intWeekDay = intDaysStayed - 4
intWeekend = 4

End If
-----Original Message-----
I posted my original question after midnight, I was prettyfrazzled by that time. I think I can state the problem
more clearly now.

I have two variable dates. Projectstart and ProjectEnd I
also have two integers projectstart.da y and projectend.daythat correspond to those dates. I want to find out
whether either of two weekend days fall in between them.
Both weekend days have a reacurring integer value based onthe week (5 and 6 because my weekends are actually friday
and saturday) though I am unsure how to refer to them in
code.
I don't have much code now, I deleted my nested if
statements when I realized it was going to be unworkable.
The idea is simple enough though I can recreate it.

Rough code:

Dim intNumberOfDays as integer
Dim intNumberOfWeek days as integer
Dim intNumberOfWeek EndDays as integer

Private Sub MonthCalendar1_ DateChanged(byV al...) Handles
dtmCharges.Dat eChanged

'Find the number of days the user selected
intNumberOfDay s = projectEnd.day - projectStart.da y

btnCalculateVa lue_click (byVal...) Handles
btnCalculateVa lue.Click

'Checking position of the project start day
'Calculate how many weekend versus weekdays based on how
'far away the start day is from the first weekend day
'then checking the total number of days selected to
'determine if it includes weekends
If projectStart.da yOfWeek = 1 and intNumberOfDays = 4 thenintNumberOfWee kDays = 3
intnumberOfWee kEndDDays = 1
else If projectStart.da yOfWeek = 1 and intNumberOfDays = 5then
intNumberOfWee kDays = 3
intNumberOfWee kEndDays = 3
else if projectStart.da yOfWeek = 1 and intNumberofDays <=3then
intnumberofWee kdays = intNumberOfDays
intnumberofWee kEndDays = 0
else if projectStart.da yOfWeek = 1 and intNumberOfDays >=6
intnumberOfWee kDays = intNumberOfDays - 2
intNumberOfWee kEndDays = 2
end if
end if
end if

end sub
end class
As you can probabaly tell Id basically have to do the samecode checking to see if the projectstart.da y was 1-7
adjusting the numerical values if the day started
Monday,Tuesday ,Wednesday,Thur sday,Friday,Sat urday or
Sunday and comparing it to the length of stay.

I hope that makes more sense then my original post.

thank you,

Sand
-----Original Message-----
* "Sand" <an*******@disc ussions.microso ft.com> scripsit:
I have a monthCalender that I want users to be able to
select a range of dates (or a single date) thencalculate a value based on the number of days that person has
selected. The values are higher for the weekends so I
need to be able to figure out how many of the selected
days are weekdays versus weekends.

I already have code to tell me the number of days the
person has selected. I also understand how to get the
DayOfWeek. I tried to code an nested if statement that would check the dayofweek, see how far away from the
weekend it is and then check that against the number of days the user selected but it has become unwieldly and, well, pretty crazy looking.

I'm hoping that someone can tell me a simpler coding
method. My other thought was maybe it's possible
something to do with the SelectedRange? I thought maybe there is a way to loop through selected range to see if dayofweek for each weekend day fell inside that rangebut I really don't know how I would do that (if it's even
possible)especi ally since dayofweek gives an integerwhile selectedrange gives dates.


Post code!

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
.

.

Nov 20 '05 #9
I'm afraid I dont really understand. I used dafediff as follows:

intTotalDays = datediff(datein terval.day, projectstart, projectend) that gives me the total number of days the user has selected as you said that returns the interval, which is the number of days between the start and end of the user selection.

If i then use datediff(datein terval.weekday, projectstart, projectend) I get some odd results that I don't know what to do with. If the user starts and thursday and goes two weeks I get a dateinterval.we ekday of 1. If the user selects Thursday and only goes one week I still get a dateinterval.we ekday or 1. In the first case they are including 2 weekend days in the second 4 but I'm getting the same result.

I don't know enough to figure out what you are saying. Can you state it in another way maybe?

Thank you so much,
Sand
Nov 20 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
3876
by: Ty Smith via AccessMonster.com | last post by:
I noticed that the week numbers in Stephan Leban's MonthCalendar are not consistent with Microsoft Outlook (they are shifted one week forward). Is there any way I can sync these two up by changing something in the module or the code in Stephan's MonthCalendar? Thanks, TySmith -- Message posted via http://www.accessmonster.com
3
14244
by: michael_hk | last post by:
Hi, I am new to Windows Form programming and now have a simple Q about MonthCalendar. I want to hightlight some days in the calendar by changing the background color of these days. But I can't find any property or method that let me do this. What I know is that I can bold them... Thanks.
13
3653
by: steven | last post by:
A monthcalendar checks every 2 minutes if theres a new day. Does anyone knows how to disable this ? The problem is that, everytime a monthcalendar checks this, the form where the monhcalendar is on, gets the focus, which is VERY annoying. Thanks, Steven
0
1362
by: steven | last post by:
Start a new project with 2 forms: one with a datagrid, a button and a monthcalendar, and another form without controls. Try this code in your form with the monthcalendar: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim frm As Form frm = New Form2 frm.Show()
8
2605
by: vbmark | last post by:
I want the MonthCalendar control to return the single day selected. I have MaxSelectionCount = 1. What I get back though is this: "SelectionRange: Start: 5/5/2005 12:00:00 AM, End: 5/5/2005 12:00:00 AM" How do I get the single day date?
3
10988
by: RG | last post by:
For a Windows project in VB.NET 2003: I need a Calendar that’s much larger than the MonthCalendar control in the toolbox; it needs to fill the whole screen (at least approximately ). VB won’t allow me to change the Size Height or Width Properties. I see that you can size a Calendar control in a Web project all you like; but I’m...
1
3507
by: DS | last post by:
I seem to have run into another strange anomaly with the monthCalendar control. I want to display 6 months at time with either the first half of the year (January-June) or the later half of the year (July-Dec) being rendered- depending on where todays date falls. I also want today's date to be selected. This poses a problem. Refer to the code...
2
5508
by: meska | last post by:
Hi all, Scenario: I have a MonthCalendar control, and DataGridView. Depending on dates displayed in MonthCalendar I want to update information from database. The Possible Solution: So I must use DateChanged and/or DateSelected events to get the new dates
11
7362
by: Randy | last post by:
I have a MonthCalendar on one of my forms. I have disovered that the DateChanged event is triggered not only when the user clicks on a new date, but also if they click on the Previous or Next Month arrows (meaning they click on either of the left or right pointing arrows in the top corner). If the user changes the month, it messes up some of...
2
2723
by: SePp | last post by:
Hi there, I have a WindowsForm which includes a label. I want to add a date to this label which a user can select. I thought it is probably the best to open another WindowsForm and to add on this one a monthcalendar. My prolbem is: How can I use this MonthcalendarForm to edit / add the date of the label on other forms.
0
7457
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7965
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7817
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5375
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5092
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3504
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3487
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1063
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
771
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.