Pstarter101
Pstarter101

Reputation: 7

vb.net manipulating textbox of what is the current time

how can i manipulate my textbox? Edit how will the form_load check the time and give the user whats textbox to use?

for like example when its

im thinking the logic of what i need is like this.

if its4pm then
textbox.text ="its 4 pm"
else if its10pm then
textbox.text = "its 10 pm"
end if

i think its simple but i find it confusing.

i tried this but it gives me an output error

    Dim date1 As Date = #7:00:00 AM#
    Dim date2 As Date = #10:00:00 AM#
    Dim date3 As Date = #1:00:00 PM#
    Dim date4 As Date = #4:00:00 PM#
    Dim date5 As Date = #7:00:00 PM#

 If TimeOfDay = date5 Then
        TextBox1.Text = "here"
        TextBox6.Text = "here"
    ElseIf TimeOfDay = date4 Then
        TextBox2.Text = "here"
        TextBox7.Text = "here"
    ElseIf TimeOfDay = date3 Then
        TextBox3.Text = "here"
        TextBox8.Text = "here"
    ElseIf TimeOfDay = date2 Then
        TextBox4.Text = "here"
        TextBox9.Text = "here"
    ElseIf TimeOfDay = date1 Then
        TextBox5.Text = "here"
        TextBox10.Text = "here"
    End If

Edit: the output error im talking about is the if else not working even it don't give me syntax error the textbox dont display "here"

Upvotes: 0

Views: 140

Answers (1)

obl
obl

Reputation: 1799

Use Now.Hour.ToString()

If Now.Hour.ToString() = "7" Then
     'code
End If

Upvotes: 1

Related Questions