Click here to Skip to main content
16,012,759 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I try to create datetime on module but when i try to check it on textbox the time just stuck in first time.. Why not like
tb1.text = datetime.now.tostring("MM/dd/yyyy HH:mm:ss")


What I have tried:

This my code in module

Public actdate As Datetime = Datetime.Now.ToString("MM/dd/yyyy HH:mm:ss")
Posted
Updated 15-Sep-17 21:03pm

1 solution

Because you are only setting it once: it does not automatically change to reflect the actual time, any more than it would if you took a Sharpie and wrote the time on your monitor.

To have a time that always reflects the current value, you need to use a timer which changes the TextBox value - probably twice a second. Exactly how you do that depends on the environment your code is working in - and we have no idea what that is!
 
Share this answer
 
Comments
Khabibb Mubarakk 16-Sep-17 5:03am    
This code without timer just place in button with handle click
tb1.text = datetime.now.tostring("MM/dd/yyyy HH:mm:ss")
give correct time when press button
But use this
 tb1.text=actdate (from module)
just give first value when button click
..no idea about this without timer?
OriginalGriff 16-Sep-17 5:37am    
Yes. Because it's a fixed time, it doesn't vary as the time passes.
When you use DateTime.Now, you get a "snapshot" of the clock at that instant: you don't get a reference to the clock because DateTime is a Value type, not a Reference type, just as an Integer is. When you use an integer value:
Dim myInt As Integer = 666;
You do not expect the value of the constant 666 to change as you alter myInt, do you? :laugh:
DateTime works the same way.
Khabibb Mubarakk 16-Sep-17 10:44am    
What going on?? All of my artcle is closed!!!
OriginalGriff 16-Sep-17 10:57am    
How would I know?
There is no sign in your rep that you ever had any!

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