Click here to Skip to main content
15,902,635 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
There's a known way to check for empty textboxes like these
 Sub Check_Textbox()
        Dim r As DialogResult
        If txtStaffID.Text = ""
Then

            r = MessageBox.Show("Please try again.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning)


But is there a way to prompt the user on a DateTimepicker? here is what and how i want the system to prompt the user:

The DateTimePicker checks the date. If it's not 3 days in advance, it will prompt the user and disallow any action.

Is the above action possible? If so, can i know the codings to it? Thanks in advance.
Posted

You can consider using the DateTimePicker ValueChanged event[^].
Handle this event, read the date value (from the event's parameters) and if the data does not meet the condition, display a message box similar to the way you were doing this for the textbox.
 
Share this answer
 
Comments
Rickysay 19-Jul-12 4:28am    
Private Sub dtpFrom_ValueChanged(ByVal sender As Object, ByVal e As EventArgs) Handles dtpFrom.ValueChanged
Dim advance As TimeSpan
Dim date1 As Date
Dim date2 As Date

date1 = Convert.ToDateTime(dtpFrom.Value)
date2 = Convert.ToDateTime(dtpFrom.Value)
advance = date2.Subtract(date1)

DateTime.Now
If dtpFrom.Value <= 3 Then
MessageBox.Show("You need to request 3 days in advance. Please Try Again.")
End If
End Sub

How do i subtract the current date to the selected date? I've tried for hours and still clueless
Simon_Whale 23-Jul-12 18:22pm    
dim thisdate as DateTime = new DateTime(2012,03,24)
dim days as double = DateTime.Now.Subtract(thisdate).TotalDays

if days <= 3 then
'do what is need here
end if
Yes, you need to write code that checks the date in your datetime picker. If you subtract one date time from another, using DateTime.Now, you get a Timespan. If the difference in days < 3, then you show your message.
 
Share this answer
 
Comments
Rickysay 18-Jul-12 21:32pm    
Can you give a coding sample?
Christian Graus 18-Jul-12 21:34pm    
No. I don't do VB at all, and if you can't even attempt it, then I'm not sure what you're doing. You know how to get the date time value to work with it, right ? You know how to subtract one value from another in code ? If this was C#, I might attempt to give a sample, even though I disapprove of people who don't learn to program because they use sites like this to get 'code samples' that they can't understand, but I feel certain if I wrote this in C#, you'd have no clue what to do with it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900