Click here to Skip to main content
15,914,351 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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.

VB
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.

What I have tried:

i tried this but it gives me an output error

VB
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
Posted
Updated 9-Mar-17 9:10am
v3
Comments
Richard MacCutchan 9-Mar-17 7:32am    
The question, and the code, are confusing. Why do you need all these different text boxes? Just provide one (or two) text boxes and process the data according to the time.

Based on what you described, below is how the code should look like although I'm not sure what you intend is. Anyway, you should only include hours and ampm for comparison.

VB
Dim date1 As Date = #7 AM#
        Dim date2 As Date = #10 AM#
        Dim date3 As Date = #3 PM#
        Dim date4 As Date = #4 PM#
        Dim date5 As Date = #2 PM#

        Dim TimeOfDay = DateTime.Now.ToString("HH tt")

        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
 
Share this answer
 
Your question is not particularly clear. If you just want to show the current time in a single textbox, use:
textbox.Text = String.Format("It's {0:h tt}", DateTime.Now)
Custom Date and Time Format Strings[^]

If you want something else, then you're going to need to explain your requirements.
 
Share this answer
 
Comments
Member 12986530 9-Mar-17 21:39pm    
i already have that. but i want my form_load to check the time and say to the user what textbox to use depends on what time it is

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900