473,386 Members | 1,752 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,386 software developers and data experts.

Date/Time Picker Questions

OK, I am fairly new to Vb, and I am doing a project for school... Does anyone know how to calculate a date, based on the date selected in the Date/Time Picker, and have it display in another text box?
Jan 20 '07 #1
12 3826
hariharanmca
1,977 1GB
OK, I am fairly new to Vb, and I am doing a project for school... Does anyone know how to calculate a date, based on the date selected in the Date/Time Picker, and have it display in another text box?

What you are calculating ?
How you are calculating?

Specify
Jan 20 '07 #2
What you are calculating ?
How you are calculating?

Specify
ok, i have a date time picker where you set it to the date that a movie is checked out, then in another box it tells you how many days the movie is allowed to be checked out, this is set automatically based on what kind of movie is checked out, With this information I am supposed to show the date due back in another text box. That is what i can not figure out. How to write the code for the due date.
Jan 20 '07 #3
Killer42
8,435 Expert 8TB
i have a date time picker where you set it to the date that a movie is checked out, then in another box it tells you how many days the movie is allowed to be checked out, this is set automatically based on what kind of movie is checked out, With this information I am supposed to show the date due back in another text box.
Use the DateAdd() function.
Jan 21 '07 #4
Use the DateAdd() function.
'ok, here is my problem, can anyone help me fill in the blanks to make this function work?
Private Sub TextBox4_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateDue.TextChanged
Dim TextBox4 As xxxxx
TextBox4.xxxxx = DateAdd(DateInterval.Day, 3, xxxxx!DateTimePicker1.Value)
End Sub
Jan 21 '07 #5
Killer42
8,435 Expert 8TB
'ok, here is my problem, can anyone help me fill in the blanks to make this function work?
Expand|Select|Wrap|Line Numbers
  1. Private Sub TextBox4_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateDue.TextChanged
  2.     Dim TextBox4 As xxxxx
  3.     TextBox4.xxxxx = DateAdd(DateInterval.Day, 3, xxxxx!DateTimePicker1.Value)
  4. End Sub
You didn't actually tell us what the problem is with this code.

I do see one potential problem, though. I would have expected TextBox4 to be already on your form, not created here in your code. Unless things have changed drastically since VB6, any object that you create within this routine will cease to exist as soon as you enter the routine.
Jan 21 '07 #6
You didn't actually tell us what the problem is with this code.

I do see one potential problem, though. I would have expected TextBox4 to be already on your form, not created here in your code. Unless things have changed drastically since VB6, any object that you create within this routine will cease to exist as soon as you enter the routine.

OK, I have changed this code, but I do not know how to use the DateAdd () function yet, so I am having a problem because I do not know how to declare the parameters... can you help? You suggested I use this function, do you know how to code it?
Jan 22 '07 #7
OK, I have changed this code, but I do not know how to use the DateAdd () function yet, so I am having a problem because I do not know how to declare the parameters... can you help? You suggested I use this function, do you know how to code it?

OOPS forgot to put the code in here...

[code] Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
'Dim "Parameters" as "What?"
TextBox1.Text = DateAdd(DateInterval.Day, +3, Parameters!DateTimePicker1.Value)
End Sub [code]
Jan 22 '07 #8
Killer42
8,435 Expert 8TB
OOPS forgot to put the code in here...

Expand|Select|Wrap|Line Numbers
  1. Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
  2.   'Dim "Parameters" as "What?"
  3.   TextBox1.Text = DateAdd(DateInterval.Day, +3, Parameters!DateTimePicker1.Value)
  4. End Sub 
Well, what you want to do is feed in a date (from your dtpicker), a unit (days) and the number to add (3). You already have those, so there is no need to create any new "parameter variable" in this routine.

Also, it looks to me as though you may be a little confused on how to use events to drive your code. Most likely, you would code this in the Change or Click event of the DTPicker (or whatever the equivalent is in your version of VB). The code would be something like
Expand|Select|Wrap|Line Numbers
  1. TextBox1.Text = DateAdd(DateInterval.Day, 3, DateTimePicker1.Value)
Oh, and just to set the record straight, in my earlier post I meant that locally created variables would disappear as soon as you exit the routine, not enter. :o

P.S. To close the CODE tag, you have to use [/CODE]
Jan 22 '07 #9
OK, first I want to say thank you for all of your help, and for being patient with me. I have changed the code to reflect the changes you suggested, and it does not give me any errors, however, it does not show the date in the textbox... this is so frustrating. I know it is probably somethign simple I am forgetting, I just can't figure it out!!

I have tried a couple of different ways. I re-created the text box and entered the code by clicking on the textbox in the design view. I tried writing the code in two different ways, and both do exactly the same thing. No errors, and no date in the text box. Here is the code I have now...

Expand|Select|Wrap|Line Numbers
  1.  Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged
  2.         Dim Result As Date
  3.  
  4.         If NewReleaseButton.Checked = True Then
  5.             Result = DateAdd(DateInterval.Day, +1, DateTimePicker1.Value)
  6.             DateDue.Text = Result
  7.         End If
  8.     End Sub 
The other way that I tried was this...

Expand|Select|Wrap|Line Numbers
  1.  Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged
  2.         DateDue.Text = DateAdd(DateInterval.Day, +1, DateTimePicker1.Value)
  3.     End Sub 
I just don't know what else to try. You mentioned something about coding it in the DateTimePicker event... what do you mean?

Again, thank you for your help!






Well, what you want to do is feed in a date (from your dtpicker), a unit (days) and the number to add (3). You already have those, so there is no need to create any new "parameter variable" in this routine.

Also, it looks to me as though you may be a little confused on how to use events to drive your code. Most likely, you would code this in the Change or Click event of the DTPicker (or whatever the equivalent is in your version of VB). The code would be something like
Expand|Select|Wrap|Line Numbers
  1. TextBox1.Text = DateAdd(DateInterval.Day, 3, DateTimePicker1.Value)
Oh, and just to set the record straight, in my earlier post I meant that locally created variables would disappear as soon as you exit the routine, not enter. :o

P.S. To close the CODE tag, you have to use [/CODE]
Jan 23 '07 #10
I just noticed something, i tried this in both the datetimepicker area and the textbox area... so technically this is only 2 of the ways i tried... the others are as follows...

Expand|Select|Wrap|Line Numbers
  1.  Private Sub DateDue_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateDue.TextChanged
  2.         Dim Result As Date
  3.  
  4.         If NewReleaseButton.Checked = True Then
  5.             Result = DateAdd(DateInterval.Day, +1, DateTimePicker1.Value)
  6.             DateDue.Text = Result
  7.         End If
  8.     End Sub 
and...

Expand|Select|Wrap|Line Numbers
  1.  Private Sub DateDue_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateDue.TextChanged
  2.          DateDue.Text = DateAdd(DateInterval.Day, +1, DateTimePicker1.Value)
  3.      End Sub 
OK, first I want to say thank you for all of your help, and for being patient with me. I have changed the code to reflect the changes you suggested, and it does not give me any errors, however, it does not show the date in the textbox... this is so frustrating. I know it is probably somethign simple I am forgetting, I just can't figure it out!!

I have tried a couple of different ways. I re-created the text box and entered the code by clicking on the textbox in the design view. I tried writing the code in two different ways, and both do exactly the same thing. No errors, and no date in the text box. Here is the code I have now...

Expand|Select|Wrap|Line Numbers
  1.  Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged
  2.         Dim Result As Date
  3.  
  4.         If NewReleaseButton.Checked = True Then
  5.             Result = DateAdd(DateInterval.Day, +1, DateTimePicker1.Value)
  6.             DateDue.Text = Result
  7.         End If
  8.     End Sub 
The other way that I tried was this...

Expand|Select|Wrap|Line Numbers
  1.  Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged
  2.         DateDue.Text = DateAdd(DateInterval.Day, +1, DateTimePicker1.Value)
  3.     End Sub 
I just don't know what else to try. You mentioned something about coding it in the DateTimePicker event... what do you mean?

Again, thank you for your help!
Jan 23 '07 #11
Killer42
8,435 Expert 8TB
Unfortunately, you're getting into the technical details of your specific version of VB now, and I'm not familiar with it.

The basic idea, though, is that you want the event which fires when you change the value in the DatePicker. It might be the ValueChanged event, which you have already tried, or it might be something like a Click event. A good way to test is to put a breakpoint in your code to make sure it is being executed, and to allow you to verify the values being used. In other words, when the date is changed in the datetime picker, we want to update the textbox. That's the way you work with events - when this happens, do that.

In VB6, I always recommend setting the option which forces you to explicitly declare all variables, rather than allowing them to be created by default. Does your version have such an option? It can prevent a lot of obscure problems.

It may be that you need to use something like the Format() function to format the date field and place it in the text box. Here's my best guess at the code. It assumes the datetimepicker is called DateTimePicker1, and the text box is called DateDue.
Expand|Select|Wrap|Line Numbers
  1. Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged
  2.   Dim Result As Date
  3.   If NewReleaseButton.Checked = True Then
  4.     Result = DateAdd(DateInterval.Day, 3, DateTimePicker1.Value)
  5.     DateDue.Text = Format(Result,"short date")
  6.   End If
  7. End Sub
Jan 23 '07 #12
Thank you, I will give that a try.

Unfortunately, you're getting into the technical details of your specific version of VB now, and I'm not familiar with it.

The basic idea, though, is that you want the event which fires when you change the value in the DatePicker. It might be the ValueChanged event, which you have already tried, or it might be something like a Click event. A good way to test is to put a breakpoint in your code to make sure it is being executed, and to allow you to verify the values being used. In other words, when the date is changed in the datetime picker, we want to update the textbox. That's the way you work with events - when this happens, do that.

In VB6, I always recommend setting the option which forces you to explicitly declare all variables, rather than allowing them to be created by default. Does your version have such an option? It can prevent a lot of obscure problems.

It may be that you need to use something like the Format() function to format the date field and place it in the text box. Here's my best guess at the code. It assumes the datetimepicker is called DateTimePicker1, and the text box is called DateDue.
Expand|Select|Wrap|Line Numbers
  1. Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged
  2.   Dim Result As Date
  3.   If NewReleaseButton.Checked = True Then
  4.     Result = DateAdd(DateInterval.Day, 3, DateTimePicker1.Value)
  5.     DateDue.Text = Format(Result,"short date")
  6.   End If
  7. End Sub
Jan 24 '07 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Adrian Parker | last post by:
Hi. I have a date time picker in my program which uses ADO to read from an Access database. It works perfectly, unless the database is empty (no records) when opened. When you try to open an...
3
by: TD | last post by:
This code doesn't work. Every posting I can find suggests that it should. If TypeOf controlname Is DTPicker then do something here End If I am using the Date Time Picker control and wish to...
7
by: XmlAdoNewbie | last post by:
Hi All, I am wondering if it is possible to allow nulls or empty strings when it comes to the datetimepicker control. I have an app with a few datetimepickers on it and there are some instances...
2
by: Need Helps | last post by:
The example given in msdn.com on how to create a Date Time Picker involves using the CreateWindowEx function. However, I created a dialog box using the graphical interface, and then used the...
4
by: Michael Turner | last post by:
Hi Guys I have two DateTime pickers one shows the Date and the other the time, this is a requirement of the solution. The problem I have is that when the time is saved to the sql database into a...
2
by: Darhl Thomason | last post by:
I'm converting my Access 2003 VBA app. I have a number of date fields in my db that I want to use the date/time picker control with, but if there is no entry in my database, I want the date/time...
1
by: dylan | last post by:
Hi, Just a few quick questions about date and time entry using html. What are the preferred methods of entering time data into a database. Eg, using two drop-down lists. And also, can...
4
by: Michel Posseth [MCP] | last post by:
I have a problem with the date time picker validate event wich i believe is a bug How to reproduce : throw on a form a date time picker control and a textbox control select the validating...
0
by: fredloh | last post by:
i have a tab control on my form. i then have several microsoft date and time picker control on the tab control. when i select a date on any of the date and time picker control, the result of the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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
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,...

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.