473,698 Members | 2,192 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2161
Hello Angelina

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

Ibrahim Malluf

Private Sub dtp2_ValueChang ed(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles dtp2.ValueChang ed

Dim MyDays As Int32

Dim Date2 As DateTimePicker = DirectCast(send er, DateTimePicker)

MyDays = DateDiff(DateIn terval.Day, dtp1.Value, Date2.Value)

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

Me.txtDays.Text = MyDays

End Sub

Private Sub dtp1_ValueChang ed(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles dtp1.ValueChang ed

Dim MyDays As Int32

Dim Date1 As DateTimePicker = DirectCast(send er, DateTimePicker)

MyDays = DateDiff(DateIn terval.Day, Date1.Value, dtp2.Value)

If MyDays < 1 Then

dtp2.Value = DateAdd(DateInt erval.Day, 1, dtp2.Value)

MyDays = DateDiff(DateIn terval.Day, Date1.Value, dtp2.Value)

End If

Me.txtDays.Text = MyDays

End Sub


"Angelina" <an*******@disc ussions.microso ft.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
"IbrahimMal luf" <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(send er, 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(DateIn terval.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(DateInt erval.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_TextCha nged(ByVal sender As Object, ByVal e As
System.EventArg s) Handles txtDays.TextCha nged

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(DateInt erval.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
"ValueChang ed" 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
501
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 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
9
3966
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 will not set the value of the control and will leave the checked status of the checkbox to false when a user selects a new date. this works fine when using the control on a win2k machine but if we use it on a win XP box and call
0
2173
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 DateTimePicker & the DateTimePicker is displayed in its expaned form (i.e displaying the calendar). If i do a datetimepicker.focus(), then the focus goes to the datetimepicker but the user who is using it might ignore the focus as
4
5682
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 logon yet this date should be empty but when binding a property to the DateTimePicker value it always shows value parsed prom property which is 1753-01-01. How to make an "empty" or "not set" date bindable to a value property of DateTimePicker?
1
1277
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 move to the date. The customer's comment was Quicken is smart enough to know that the month is done and move to the day. Is there an option to move to the day (or year), or automatically have the cursor on the day when the control has focus? ...
7
6206
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 the DateTimePicker, since the default is shown. My problem is, if the user does not choose a value from the DateTimePicker (because using the default is good enough), then during database update, the date value is not saved to the database; while if...
3
6381
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 checkbox is focused?
2
1727
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 cursor to the DD and then the YYYY without needing to use the "/" key?? So the keystrokes look like "07041978" versus doing "07/04/1978". Secondly - if we don't know the D.O.B. at the time of input, we'd like to make update the dataset with a...
3
7513
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 on. It's a simple program that loads a control onto a form and binds "Foo" against a combobox ("SelectedItem") for it's "Bar" property and a datetimepicker ("Value") for it's "DateTime" property. The DateTimePicker.Visible value is set to...
4
3296
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 go about representing this to a user so they are not confused? Thanks,
0
8674
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8603
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9026
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8893
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8861
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7723
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6518
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3045
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.