Question

How can I make it so that when I load the form a textbox will show me (dd/mm/yyy hh:mm:ss) format clock that is actually moving and is synced with the system?

I tried googling it but so far couldn't find anything that works. Most answers dealt with making labels into clocks but I figured it's the same with textboxes and tried doing what they said with no results. It shows me the time but it's just the time when the form loaded not an actual moving clock. I think most of the answers I found on google are dealing with older versions of VB that's why I can't get it to work.

P.S. I'm just learning coding so the simpler the code the better. Many step by step (like I'm 5) comments are appreciated as well. Thank You

Was it helpful?

Solution

Add a Timer to your form, and add this code to it's tick event.

 Textbox1.text = Format(Now, "yyyy-MM-dd hh:mm:ss")

You now have a textbox which tells you the current date and time. Don't forget to enable your timer, though!

OTHER TIPS

Try to put your time and date string inside a timer. this is how it looks like:

Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick

    TimerText.Text = TimeString
    DaterText.Text = DateString

End Sub

It will surely show you a moving/real time clock that was sync to your computer. :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top