473,406 Members | 2,377 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

DateTimePicker questions

Hi,

I have got two DateTimePicker's on my form to accept a
guest arrival date and departure date.what i want to
acheieve is ensure that the DateTimePicker2 (departure)
is always greater than DateTimePicker1 (arrival date).
can anyone help me on the code for this? as u can tell,
im new learner.

i also want the days between the arrival date and
deparure date to be displayed in a 'length of stay
textbox'. i.e 2 nights stay.
or i want it so if they select a arrival date and enter 3
nights stay in the 'length of stay textbox' to adjust the
departure date automatically. Is this possible. can any
one help me on this coding or point me in the right
direction for any useful reasources.

Thx
Nov 22 '05 #1
2 2128
Hello Angelina

dtp1 and dpt in the code below are datetimepickers. Hope this helps

Ibrahim Malluf

Private Sub dtp2_ValueChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles dtp2.ValueChanged

Dim MyDays As Int32

Dim Date2 As DateTimePicker = DirectCast(sender, DateTimePicker)

MyDays = DateDiff(DateInterval.Day, dtp1.Value, Date2.Value)

If MyDays < 1 Then Date2.Value = DateAdd(DateInterval.Day, 1, Date2.Value)

Me.txtDays.Text = MyDays

End Sub

Private Sub dtp1_ValueChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles dtp1.ValueChanged

Dim MyDays As Int32

Dim Date1 As DateTimePicker = DirectCast(sender, DateTimePicker)

MyDays = DateDiff(DateInterval.Day, Date1.Value, dtp2.Value)

If MyDays < 1 Then

dtp2.Value = DateAdd(DateInterval.Day, 1, dtp2.Value)

MyDays = DateDiff(DateInterval.Day, Date1.Value, dtp2.Value)

End If

Me.txtDays.Text = MyDays

End Sub


"Angelina" <an*******@discussions.microsoft.com> wrote in message
news:06****************************@phx.gbl...
Hi,

I have got two DateTimePicker's on my form to accept a
guest arrival date and departure date.what i want to
acheieve is ensure that the DateTimePicker2 (departure)
is always greater than DateTimePicker1 (arrival date).
can anyone help me on the code for this? as u can tell,
im new learner.

i also want the days between the arrival date and
deparure date to be displayed in a 'length of stay
textbox'. i.e 2 nights stay.
or i want it so if they select a arrival date and enter 3
nights stay in the 'length of stay textbox' to adjust the
departure date automatically. Is this possible. can any
one help me on this coding or point me in the right
direction for any useful reasources.

Thx

Nov 22 '05 #2
"IbrahimMalluf" <Ib*****@malluf.com> wrote...

Hello... I like to study code because I always learn something from it... I
have some comments and questions if you don't mind.

First:
Dim Date2 As DateTimePicker = DirectCast(sender, DateTimePicker)
That's cool but it's the only control not referenced by name. Is there a
reason you are willing to access Me.txtDays and Me.dtp1 but decided not to
access dtp2.Value directly in the dtp2 event handler (and dtp1.Value in the
dtp1 event handler?)

And MyDays should really be a Long I believe...
Dim MyDays As Long = DateDiff(DateInterval.Day, Me.dt1.Value, Me.dt2.Value)

To accomodate the length of the stay this line should add the number of
days in the textbox rather than 1.
If MyDays < 1 Then
dtp2.Value = DateAdd(DateInterval.Day, 1, dtp2.Value)
Strictly speaking the assignment ought to be through MyDays.ToString Me.txtDays.Text = MyDays.ToString

And I added a handler for the textbox:

Private Sub txtDays_TextChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles txtDays.TextChanged

Dim days As Double = Val(Me.txtDays.Text)

If (days < 0) Then
days = 0
Me.txtDays.Text = days.ToString
End If

Me.dtp2.Value = DateAdd(DateInterval.Day, Val(Me.txtDays.Text),
dtp1.Value)

End Sub
And my question... if you (or somebody knows)

What causes Windows to stop looping between events when all the
"ValueChanged" handlers are changing the values of other controls. I notice
the other event handlers are called by first event handler but it eventually
exits.

Nov 22 '05 #3

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

Similar topics

2
by: Angelina | last post by:
Hi, I have got two DateTimePicker's on my form to accept a guest arrival date and departure date.what i want to acheieve is ensure that the DateTimePicker2 (departure) is always greater than...
9
by: Guy | last post by:
I have extended the datetimepicker control to incorporate a ReadOnly property. I have used the new keyword to implement my own version of the value property, so that if readonly == true then it...
0
by: Sumit | last post by:
Hi all, I have a datetimepicker on my windows form. When the user selects it i check whether the date entered is a Sunday or not & if its not a sunday i want that the control remains on the...
4
by: Jacek Jurkowski | last post by:
.... the minimum date of DateTimePicker is 1753-01-01. How to make DateTime to do not show nothing in its text if this date is the value? I have a form with a field LastLogonDate. If user hasn't...
1
by: Darin | last post by:
A customer asked this question and I don't see how it can be done. Currently, when using the datetimepicker, after you enter the month you have to either hit the right arrow or the "/" for it to...
7
by: Clamara | last post by:
When adding a new record from my form, I pre-set my DateTimePicker's value to System.DateTime.Today Since the "Today" value is used most of the time, the user doesn't need to select a date from...
3
by: Charlie | last post by:
In the top portion of the DateTimePicker, where the value of the date is displayed, how can I detect whether the month or day or year is currently focused, or, if ShowCheckBox = True, whether the...
2
by: mafandon | last post by:
This example deals with a datetimepicker Date of Birth concept for a windows form in VB 2005. Simply put, if a user wants to enter the MM/DD/YYYY using the number pad, how can I advance the...
3
by: Simon Tamman | last post by:
I've come across an interesting bug. I have workarounds but i'd like to know the root of the problem. I've stripped it down into a short file and hope someone might have an idea about what's going...
4
by: jehugaleahsa | last post by:
Hello: We were hoping to allow users to have DateTimePicker value null so that a unused date is stored on a Database. Does the control support this? I am pretty sure it doesn't. How would you...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.