Home All Groups Group Topic Archive Search About

Add to a user inputted date

Author
7 Aug 2006 8:29 PM
bryan.a.fowler
I'm really new working with VB.net and I'm working on a simple program
with a date input. I've got a couple of questions;

1) I'm using a DateTimePicker to show both the user inputted date as
well as the calculated date. Is this a good way to do this or is there
an easier way?

2) I can't seem to get the code right to take the user inputted date to
output to the new calculated date. This is my code so far;

Dim MyDate As Date
Dim MyDate2 As Date
Dim CompDate As Date

Private Sub DateMyPick_ValueChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles DateMyPick.ValueChanged
'----Set Variable to this value----'
MyDate = DateMyPick.Value

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
MyDate2 = Convert.ToDateTime("MyDate"
CompDate = MyDate2.AddMonths(3)
DateCompPick.Value = CompDate

Is this about right or am I way off base? It compiles fine, but when I
go in, and actually click the button, I get an error message;

"An unhandled exception of type 'System.FormatException' occured in
mscorlib.dll  Additional information: The stirng was not recognized as
a valid DateTime. There is an unknown word starting at index 0."

Any and all help would be greatly appreciated. Thanks!

Author
7 Aug 2006 8:48 PM
GhostInAK
Hello bryan.a.fow***@gmail.com,

Double-quote marks indicate a string.  The string "MyDate" is not a date
in any country that I know of.  Try using the variable directly.
This would eliminate the non-existant need for MyDate2.

-Boo

Show quoteHide quote
> Dim MyDate As Date
> Dim MyDate2 As Date
> Dim CompDate As Date
> Private Sub DateMyPick_ValueChanged(ByVal sender As System.Object,
> ByVal e As System.EventArgs) Handles DateMyPick.ValueChanged
> '----Set Variable to this value----'
> MyDate = DateMyPick.Value
> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles Button1.Click
> MyDate2 = Convert.ToDateTime("MyDate"
> CompDate = MyDate2.AddMonths(3)
> DateCompPick.Value = CompDate
Author
8 Aug 2006 1:08 PM
BryanA
Thanks...

I took out the;

MyDate2 = Convert.ToDateTime("MyDate")

and I put everything back to MyDate, and it works now. Thanks a bunch!

GhostInAK wrote:
Show quoteHide quote
> Hello bryan.a.fow***@gmail.com,
>
> Double-quote marks indicate a string.  The string "MyDate" is not a date
> in any country that I know of.  Try using the variable directly.
> This would eliminate the non-existant need for MyDate2.
>
> -Boo
>
> > Dim MyDate As Date
> > Dim MyDate2 As Date
> > Dim CompDate As Date
> > Private Sub DateMyPick_ValueChanged(ByVal sender As System.Object,
> > ByVal e As System.EventArgs) Handles DateMyPick.ValueChanged
> > '----Set Variable to this value----'
> > MyDate = DateMyPick.Value
> > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
> > System.EventArgs) Handles Button1.Click
> > MyDate2 = Convert.ToDateTime("MyDate"
> > CompDate = MyDate2.AddMonths(3)
> > DateCompPick.Value = CompDate