How do I return a certain date into a textbox based on a DateTimePicker date using VB.net Framework 8.0?

65 Views Asked by At

I am creating a desktop version of a program that I use a DateTimePicker formatted as Short. I have a textbox that I want to display a date based on the DateTimePicker with a very specific formula. I've looked all over the internet and can't find an answer to this very specific need.

I do not have code to share at this moment. Here is a rundown of what I do have.

I have the Date in the DateTimePicker. I have the Textbox where I want the new date. I have a formula that I need to apply to the DateTimePicker value.

The formula is X = DateTimePicker + (Y * 30).

Pretty basic but I can't figure out how to "Marry" the DateTimePicker value with the formula and get a new date.

I tried different methods based on research from forums, including StackOverflow but have had no success.

I'm hoping someone will be able to help me in getting this to work.

1

There are 1 best solutions below

3
Idle_Mind On

From the comments:

here is the actual formula. SecondDate = DateTimePicker + (EstimatedHoldTime(InMonths) * 30) I am trying to get SecondDate based on this formula. Not adding months or a certain amount of days. SecondDate is a Textbox, DateTimePicker is a DateTimePicker Box, EstimatedHoldTime(Months) is a Textbox As Double, 30 is a Fixed Number

Here's an example:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim value As Double
    If (Double.TryParse(EstimatedHoldTime(Months).Text, value)) Then
        Dim dt As DateTime = DateTimePicker.Value.AddDays(value * 30)
        SecondDate.Text = dt.ToShortDateString()
    Else
        MessageBox.Show("Invalid Hold Time!")
    End If
End Sub