|
-
Jan 21st, 2010, 02:16 AM
#1
Re: [RESOLVED] Plotting Real Time Graph
-
Jan 21st, 2010, 03:16 AM
#2
Thread Starter
Lively Member
Re: [RESOLVED] Plotting Real Time Graph
Thanks MaximilianMayrhofer! =)
But i still dont really understanding the following, please forgive me as i may be poor in understanding.
For example:
Code:
Dim dt As DateTime = DateTime.Now
Dim ts As TimeSpan = dt - StartTime
Label1.Text = ts.Hours.ToString & ":" & ts.Minutes.ToString & ":" & CInt(ts.Seconds).ToString
ts = dt.AddSeconds(1) - StartTime
So for example, the time now is 4:01:35PM.
Since dt is (DateTime.Now), which is 4:01:35PM,
and ts is (dt-StartTime), so it will mean [ ts = (4:01:35) - StartTime ] correct?
But the StartTime, as in the beginning, 00:00:00 ?
Then for, ts = dt.AddSeconds(1) - StartTime, it will be :
>> ts = 4:01:35.AddSeconds(1) - 00:00:00
which will be:= 4:01:36 - 00:00:00
The above doesnt make sense to me, so I believe my concept towards the above is wrong, therefore i would appreciate if someone could explain to me how it works. 
Apologies if the above is unclear. Because i cant really understand how the above subtraction will allow my timer to start from 00:00:00 , 00:00:01, 00:00:02, so on and so forth.. 
Thanks in advance for the help!
.
-
Jan 21st, 2010, 05:39 AM
#3
Re: [RESOLVED] Plotting Real Time Graph
 Originally Posted by catherine0136
But the StartTime, as in the beginning, 00:00:00 ?
If I remember correctly, there was a point earlier in the program where you had:
Code:
StartTime = DateTime.Now
So StartTime contains a snapshot of whatever the system time was at that particular moment. (Hint: if you don't know about using BreakPoints yet, it's a good time to learn it.)
DateTimes and TimeSpans are confusing because they are not like ordinary numbers. If you subtract two Integers you get another Integer as you'd expect:
Code:
Dim Lots As Integer = 1000
Dim NotSoMuch As Integer = Lots - 250
TextBox1.Text = NotSoMuch.ToString
and TextBox1 will obligingly show 750. It's exactly like you learned it in algebra. But if you try to subtract two DateTimes, you don't get another DateTime but a TimeSpan instead. You are allowed to use a minus sign for two DateTimes but it has a different meaning to the minus sign used for arithmetic. It's just the way people at Microsoft designed it. And you can't write:
Code:
Dim dt As DateTime = DateTime.Now
dt = dt + 5
Instead you have to use AddSeconds or SubtractSeconds. What is more dt.AddSeconds(5) doesn't change the value of dt the way + does with integers. Instead it produces a new DateTime with the required value.
Things like DateTime and TimeSpan are called Reference Types, as opposed to Value Types (like Integers). A String is another example of a reference type, and similarly it has rules of its own for "adding" strings together. You'll get used to them, I hope .
BB
Last edited by boops boops; Jan 21st, 2010 at 07:06 AM.
-
Jan 21st, 2010, 08:07 PM
#4
Thread Starter
Lively Member
Re: [RESOLVED] Plotting Real Time Graph
@ BB,
Arh, i understand what you meant already!! 
Thanks! =)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|