Add to a user inputted date

B

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!
 
G

GhostInAK

Hello (e-mail address removed),

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
 
B

BryanA

Thanks...

I took out the;

MyDate2 = Convert.ToDateTime("MyDate")

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top