|
add the timer control your form
set the interval to 1000
in the event routine, use the keyword 'now' and format it to be hh:nn:ss and keep replacing the value of the cell with the result
|
|
|
|
|
Thanks for you reply. could show me how to add 'now' and format it to be hh:nn:ss ...
I am adding item to listview like this :
ListView1.ListItems(1).ListSubItems(3).Text = "changed2"
so how to add running time instead of change2? Do you think using this method will make the listview reload every seconds? i hope that is not the case since it will disturb form focus. I have seen applications that they add running time to listview column without any listview reload every seconds .
|
|
|
|
|
vb6 - format(now,"hh:nn:ss")
vb.net - now.tostring("hh:mm:ss")
|
|
|
|
|
Thanks for you reply. I tried the following and it only display the current time!! I wanted to start from 00:00:00 and start running
ListView1.ListItems(1).ListSubItems(4).Text = Format(Now, "hh:nn:ss")
|
|
|
|
|
make a module level variable that will hold to the current ticks
private mStartDate As Double = Now.Ticks
in the timer event routine
Dim s As String = TimeSpan.FromTicks(Now.Ticks - mStartDate).ToString
ListView1.ListItems(1).ListSubItems(4).Text = s.Substring(0, s.IndexOf("."))
|
|
|
|
|
I placed "private mStartDate As Double = Now.Ticks: inside a module.
Then i added timer to the form an set its interval to 1000.Then i added following code:
<br />
Private Sub Form_Load()<br />
<br />
<br />
Timer2.Interval = 1000 ' <-- 10 seconds<br />
Timer2.Enabled = True<br />
End Sub<br />
<br />
Private Sub Timer2_Timer()<br />
Static lngMin As Long<br />
<br />
lngMin = lngMin + 1<br />
<br />
'every 2nd timer tick reload the listview<br />
If lngMin Mod 2 Then<br />
<br />
Dim s As String = TimeSpan.FromTicks(Now.Ticks - mStartDate).ToString<br />
ListView1.ListItems(1).ListSubItems(4).Text = s.Substring(0, s.IndexOf("."))<br />
<br />
End If<br />
<br />
End Sub<br />
<br />
then i get compile error :
Expected: end of statement
pointing at:
private mStartDate As Double = Now.Ticks
|
|
|
|
|
this is vb6? i didn't think vb6 had listviews
you can always create the time manually but I'll try to come up with vb6 equvilent...
|
|
|
|
|
Many thanks for trying to help me . I am working on vb6 for this project. VB6 has listviews by selecting Microsoft windows common controls 6.0(sp6) component. I have seen a few applications not sure what programing language they are written it .They add timer to listview without noticing any flicker or reload!!
|
|
|
|
|
***make a module level variable***
private mStart as single
***in the load event of the form***
mStart = Timer
***in the timer event routine***
ListView1.ListItems(1).ListSubItems(4).Text = Format(TimeSerial(0, 0, cint(Timer - mStart), "hh:nn:ss")
-- modified at 17:26 Friday 11th May, 2007
|
|
|
|
|
I tried it i get the following error:
compile error:
syntax error
pointing at :
ListView1.ListItems(1).ListSubItems(4).Text = Format(TimeSerial(0, 0, cint(Timer - mStart), "hh:nn:ss")
|
|
|
|
|
sorry...add a paren after the cint
Format(TimeSerial(0, 0, cint(Timer - mStart)), "hh:nn:ss")
|
|
|
|
|
Now i get this error in the same line:
Run-time error 6:<br />
<br />
overflow
|
|
|
|
|
ok, use clng instead of cint
|
|
|
|
|
same overflow error (
Private Sub Form_Load()<br />
mStart = Timer<br />
<br />
'Set up the listview<br />
ListView1.View = lvwReport<br />
ListView1.ColumnHeaders.Add , , "Artist"<br />
ListView1.ColumnHeaders.Add , , "Name"<br />
ListView1.ColumnHeaders.Add , , "Image"<br />
ListView1.ColumnHeaders.Add , , "Rating"<br />
'ListView1.ColumnHeaders.Add , , "Song ID"<br />
ListView1.ColumnHeaders.Add , , "Total Votes"<br />
ListView1.ColumnHeaders.Add , , "Page"<br />
ListView1.ColumnHeaders.Add , , "Referrer"<br />
ListView1.ColumnHeaders.Add , , "pageWindowName"<br />
<br />
<br />
Timer1.Interval = 1000 ' <-- 10 seconds<br />
Timer1.Enabled = True<br />
<br />
<br />
End Sub<br />
<br />
Private Sub Timer1_Timer()<br />
<br />
ListView1.ListItems(1).ListSubItems(4).Text = Format(TimeSerial(0, 0, CLng(Timer - mStart)), "hh:nn:ss")<br />
<br />
End Sub
|
|
|
|
|
anyone have a function that converts milliseonds to minutes and seconds?
im working in vb.net. thanks a bunch.
|
|
|
|
|
You can either write this function yourself, the math is very easy, or you can use the TimeSpan class to do it for you.
Dim x As New TimeSpan(0, 0, 0, 0, milliseconds)
Console.WriteLine("Minutes: " & x.Minutes)
Console.WriteLine("Seconds: " & x.Seconds)
|
|
|
|
|
|
Of course we don't care about rounding...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
CPallini wrote: Of course we don't care about rounding...
The exact specifics of which are left up to the reader, depending on specifications of course!
|
|
|
|
|
According to http://www.int.gu.edu.au/courses/3008int/m03/FYI/Command_Syntax.htm#Heading97[^]
"Int Function
Int(number)
Returns the integer portion of the number specified by the number argument. If number is negative, then Int returns the first negative integer less than or equal to number."
So please explain this behavior.
This is the current line of code.
strValue = CStr(Int(CSng(Mid(strInput, 50, 7)) + 0.5)) which gives me -9.0 when the value is -8.12. Logically -8.62 + 0.5 = -8.12.
If I change this to VB.NET code.
strValue = (Convert.ToInt32(Convert.ToSingle(strInput.Substring(50, 7)) + 0.5)).ToString Then I get -8.12.
What is up with that and if I indeed need it to be -9 how do I get there?
CleaKO
"I think you'll be okay here, they have a thin candy shell. 'Surprised you didn't know that.'" - Tommy (Tommy Boy) "Fill it up again! Fill it up again! Once it hits your lips, it's so good!" - Frank the Tank (Old School)
|
|
|
|
|
With this code you shoudl get -8 . The documentation is a little misleading. It should say that it gives you the integer closest to 0. If you have -8.12 the value returned would be -8 .
So what's the point of all this? Are you trying to round down to the next lower integer, be it a positive or negative value? -9 is lower than -8.12 for example.
|
|
|
|
|
Dave Kreskowiak wrote: So what's the point of all this? Are you trying to round down to the next lower integer, be it a positive or negative value? -9 is lower than -8.12 for example.
Based on what the code is doing it would appear that it should literally move it to the next highest number and cut it off at the decimal. The problem is when I simply converted the values to a more .NET way of coding. The .NET way gives me the answer I would expect, the VB6 way does not. It almost seems to ignore the fact that it is negative so the numbers go the other way when rounding UP. This is a production system so I need it to give the same answers and I can worry about whether they are correct after I get a match.
-- modified at 11:39 Thursday 10th May, 2007
It would appear that it always rounds to the number lower not closer to zero so -8.12 goes to -9 whereas 20.8 goes to 20. That seems like a bug to me.
CleaKO
"I think you'll be okay here, they have a thin candy shell. 'Surprised you didn't know that.'" - Tommy (Tommy Boy) "Fill it up again! Fill it up again! Once it hits your lips, it's so good!" - Frank the Tank (Old School)
|
|
|
|
|
CleaKO wrote: It would appear that it always rounds to the number lower not closer to zero so -8.12 goes to -9 whereas 20.8 goes to 20. That seems like a bug to me.
Not quite. OK. I didn't notice this before, but the Int function is NOT the same as CInt .
In VB6, if you do this:
CInt(Csng("-8.62") + 0.5) you get -8 .
If you do this:
Int(Csng("-8.62") + 0.5) you get -9 .
Why? The answer is in the documentation:
Int, Fix Functions[^]
Both Int and Fix remove the fractional part of a number and return the resulting integer value.
The difference between Int and Fix is that if the number is negative, Int returns the first negative integer less than or equal to that number, whereas Fix returns the first negative integer greater than or equal to that number. For example, Int converts -8.4 to -9, and Fix converts -8.4 to -8.
Cint()[^]
CInt differs from the Fix and Int functions, which truncate, rather than round, the fractional part of a number. When the fractional part is exactly 0.5, the CInt function always rounds it to the nearest even number. For example, 0.5 rounds to 0, and 1.5 rounds to 2.
Under VB.NET, the CInt and Convert.ToInt32() methods follow the old VB6 CInt function. You can still use the original VB6 code VB.NET, the Int function IS still there.
|
|
|
|
|
Dave Kreskowiak wrote: Why? The answer is in the documentation:
Int, Fix Functions[^]
Both Int and Fix remove the fractional part of a number and return the resulting integer value.
The difference between Int and Fix is that if the number is negative, Int returns the first negative integer less than or equal to that number, whereas Fix returns the first negative integer greater than or equal to that number. For example, Int converts -8.4 to -9, and Fix converts -8.4 to -8.
Cint()[^]
CInt differs from the Fix and Int functions, which truncate, rather than round, the fractional part of a number. When the fractional part is exactly 0.5, the CInt function always rounds it to the nearest even number. For example, 0.5 rounds to 0, and 1.5 rounds to 2.
Under VB.NET, the CInt and Convert.ToInt32() methods follow the old VB6 CInt function. You can still use the original VB6 code VB.NET, the Int function IS still there.
Thanks for the clarification.
I know the function is still there, I just like to try to get away from the VB6 versions if I can. Maybe Im just a little too strict with my .NET.
CleaKO
"I think you'll be okay here, they have a thin candy shell. 'Surprised you didn't know that.'" - Tommy (Tommy Boy) "Fill it up again! Fill it up again! Once it hits your lips, it's so good!" - Frank the Tank (Old School)
|
|
|
|
|
The VB6 functions are equivalent to these .NET methods:
Int() -> Math.Floor()<br />
Fix() -> Math.Ceiling()<br />
Round() -> Math.Round()<br />
CSng() -> Convert.ToSingle()<br />
CLng() -> Convert.ToInt32()
The Convert.ToInt32 method rounds the value the same ways as Math.Round does.
---
single minded; short sighted; long gone;
|
|
|
|
|