Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DateTimePicker date selected

I'm having some problems with my Visual Basic Project.

Im making a program which desplays if there come out any new TV series in the US/ Available for download (next day)

(US and Torrent are days in Swedish)

enter image description here

So I have done that but I want to add a DateTimePicker, so I can select a day and then check whats Available. Well I noticed that the DateTimePicker always starts at the current date so I just added it like so:

Dim DateTimePickerDay = Me.DateTimePicker1.Value.DayOfWeek.ToString()

Dim USstatus = "Tomorrow"
Dim DownloadStatus = "Today"

If DateTimePickerDay = "Monday" Then
  StatusLabel1.Text = USstatus
  StatusLabel1.ForeColor = Color.Blue
  StatusLabel5.Text = DownloadStatus
  StatusLabel5.ForeColor = Color.Green
  StatusLabel6.Text = DownloadStatus
  StatusLabel6.ForeColor = Color.Green
End If

But now I want to be able to change the day using the DateTimePicker and see whats available for that day. So I tried to change a Lebel to the day like so:

Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
  Me.Label4.Text = Me.DateTimePicker1.Value.DayOfWeek.ToString()
End Sub

and then:

If Me.Label4.Text = "Monday" Then
  StatusLabel1.Text = USstatus
  StatusLabel1.ForeColor = Color.Blue
  StatusLabel5.Text = DownloadStatus
  StatusLabel5.ForeColor = Color.Green
  StatusLabel6.Text = DownloadStatus
  StatusLabel6.ForeColor = Color.Green
End If

So when the Label says "Monday", which it does if I choose Monday. It's going to show which series are available on Monday. Well this doesn't work and I can't figure out why.

Can anyone explain for me how I can get this working and what do I do wrong?

like image 706
David Avatar asked Mar 17 '26 04:03

David


1 Answers

You should base the comparison on the DayOfWeek enumeration instead of a string

If Me.DateTimePicker1.Value.DayOfWeek = DayOfWeek.Monday Then
    ...
End If

and also check if the user selected a date in the ValueChanged event of the DateTimePicker as Chris already mentioned in his answer.

like image 117
Olivier Jacot-Descombes Avatar answered Mar 20 '26 09:03

Olivier Jacot-Descombes



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!