Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This might be an easy problem to resolve. I have a text box that gets populated with the current date using
VB
DateTime.Now.ToString("MM/dd/yyyy")
. My question is when the application is running how do I create a loop to have that field auto populate the date again if the application is running over night and the Now.Date has changed?

What I have tried:

I have not tired anything as of yet, but wondering what would be better a "IF loop" statement or a timer style would better.
Posted
Updated 16-Nov-17 7:47am
Comments
A_Griffin 16-Nov-17 13:20pm    
Use a timer control (I'm assuming this is a desktop application?)
KD209 16-Nov-17 13:37pm    
Yes, this is a desktop application.
A_Griffin 16-Nov-17 13:43pm    
Well then definitely a timer control over any kind of loop - it's the sort of thing they were designed for. You could have your box update every second if you want without eating computer resources.

1 solution

Adding the timer worked
myTimer.Enabled = True
        myTimer.Interval = 1000
and
VB
Private Sub myTimer_Tick(sender As Object, e As EventArgs) Handles myTimer.Tick

    TextBox5.Text = DateTime.Now.ToString("MM-dd-yyyy")

End Sub
 
Share this answer
 

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