How to add clock timer to listview column ?

You can talk about VB programming here

How to add clock timer to listview column ?

Postby method » Tue May 08, 2007 1:41 pm


could any one show me how i can add clock timer that shows hour:min:seconds to a perticuler listview column ?
method
imFiles Master
imFiles Master
 
Posts: 686
Joined: Tue Oct 18, 2005 11:12 am

Postby BattleStar-Galactica » Tue May 08, 2007 9:32 pm

use paint to draw what you want for that, I didn't get it because my poor english vocabulary

btw you can find the formula convert second to hour format hh:mm:ss
Last edited by BattleStar-Galactica on Tue May 08, 2007 9:33 pm, edited 1 time in total.
Big math problem
2 - 1 = 0 = without you I'm nothing
User avatar
BattleStar-Galactica
imFiles Master
imFiles Master
 
Posts: 565
Joined: Tue Sep 20, 2005 12:19 am
Location: safest place to hide

Postby method » Sat May 12, 2007 12:51 am

lol.What paint? could you show me a vb6 code?
method
imFiles Master
imFiles Master
 
Posts: 686
Joined: Tue Oct 18, 2005 11:12 am

Postby sk8er » Sun May 13, 2007 7:25 am

listview1.text = time?
you dont know who i am, and i would rather keep it that way.
sk8er
Co-Admin
Co-Admin
 
Posts: 541
Joined: Thu Nov 25, 2004 1:23 pm
Location: here

Postby method » Sun May 13, 2007 11:53 am

I mean running timer not just time!!! without any flicking!!

see the clip and you will know what i am looking for

http://www.zshare.net/video/timer-avi.html
Last edited by method on Sun May 13, 2007 12:29 pm, edited 1 time in total.
method
imFiles Master
imFiles Master
 
Posts: 686
Joined: Tue Oct 18, 2005 11:12 am

Postby BattleStar-Galactica » Sun May 13, 2007 8:33 pm

now is clear


but think with me to arrive that result, want you?

first we need a timer(because vb6) to get datetime every second

when we get a total seconds and want to display as format hh:mm:ss

do some thing like this

[vb]Dim lHrs As Long
Dim lMinutes As Long
Dim lSeconds As Long

lSeconds = 150 '<<<for this example purpose we put 150 seconds

lHrs = Int(lSeconds / 3600)
lMinutes = (Int(lSeconds / 60)) - (lHrs * 60)
lSeconds = Int(lSeconds Mod 60)[/vb]

and now format it to the format as we needed hh:mm:ss

[vb]yourresulthere = Format$(lHrs,"00") & ":" & Format$(lMinutes,"00") & ":" & Format$(lSeconds,"00")[/vb]

[Ghost's edit] OMG OMG OMG! USE TEH VB TAGS! THAT'S WHAT THEY'RE THERE FOR! [/Ghost's edit]
Last edited by BattleStar-Galactica on Sun May 13, 2007 8:42 pm, edited 2 times in total.
Big math problem
2 - 1 = 0 = without you I'm nothing
User avatar
BattleStar-Galactica
imFiles Master
imFiles Master
 
Posts: 565
Joined: Tue Sep 20, 2005 12:19 am
Location: safest place to hide

Postby method » Sun May 13, 2007 11:11 pm

BattleStar-Galactica Thanks for trying to help me. should i put all these inside a timer? could you explain to me how to make this running on a listview? I hope this a method with no flicker as shown in video . Because i don't want my other listview data get disturbed by reload of every second. Is this flicker free method?

How to make it start from 00:00:00 and go upward just like stop watch ?
Last edited by method on Sun May 13, 2007 11:48 pm, edited 2 times in total.
method
imFiles Master
imFiles Master
 
Posts: 686
Joined: Tue Oct 18, 2005 11:12 am

Postby BattleStar-Galactica » Mon May 14, 2007 12:07 am

this line >> lSeconds = 150 '<<<for this example purpose we Put 150 seconds


to lSeconds = 0

you will get 00:00:00

for free flicker call DoEVents method in vb6. I'm not sure about the exact function name but something like that

I think colo can give you a hand cuz he sleep and eat with vb, i'm not.
Last edited by BattleStar-Galactica on Mon May 14, 2007 12:15 am, edited 1 time in total.
Big math problem
2 - 1 = 0 = without you I'm nothing
User avatar
BattleStar-Galactica
imFiles Master
imFiles Master
 
Posts: 565
Joined: Tue Sep 20, 2005 12:19 am
Location: safest place to hide

Postby method » Mon May 14, 2007 12:16 am

I placed you code inside timer and it never runs. It stays at 00:00:00!!


[vb]Dim lHrs As Long
Dim lMinutes As Long
Dim lSeconds As Long

lSeconds = 0 '<<<for this example purpose we Put 150 seconds

lHrs = Int(lSeconds / 3600)
lMinutes = (Int(lSeconds / 60)) - (lHrs * 60)
lSeconds = Int(lSeconds Mod 60)

'yourresulthere = Format$(lHrs,"00") & ":" & Format$(lMinutes,"00") & ":" & Format$(lSeconds,"00")


ListView1.ListItems(1).ListSubItems(1).Text = Format$(lHrs, "00") & ":" & Format$(lMinutes, "00") & ":" & Format$(lSeconds, "00")[/vb]

I even placed a msgbox at the end timer and saw that timer is actually running but the timer is not!!
Last edited by method on Mon May 14, 2007 12:17 am, edited 2 times in total.
method
imFiles Master
imFiles Master
 
Posts: 686
Joined: Tue Oct 18, 2005 11:12 am

Postby BattleStar-Galactica » Mon May 14, 2007 12:21 am

increment lSeconds variable like this lSeconds = lSeconds + 1

ah you have to put lSeconds in global if you want to keep it value
post your project here I can check it for u
Last edited by BattleStar-Galactica on Mon May 14, 2007 12:23 am, edited 1 time in total.
Big math problem
2 - 1 = 0 = without you I'm nothing
User avatar
BattleStar-Galactica
imFiles Master
imFiles Master
 
Posts: 565
Joined: Tue Sep 20, 2005 12:19 am
Location: safest place to hide

Postby method » Mon May 14, 2007 12:32 am

Here is the project. I created a modul and declared lSeconds as shown but still didn't work!!

Modul:
[vb]Option Explicit
'i am declaring varibles that be avalible every where

Public lSeconds As Integer[/vb]


[vb]Private Sub Form_Load()
Dim itmx As ListItem
Dim colx As ColumnHeader

'Add Some Columns
Set colx = ListView1.ColumnHeaders.Add(, , "Col1")
Set colx = ListView1.ColumnHeaders.Add(, , "Col2")

'Add two items
Set itmx = ListView1.ListItems.Add(, , "ABC")
itmx.SubItems(1) = "XYZ"

Set itmx = ListView1.ListItems.Add(, , "XYZ")
itmx.SubItems(1) = "ABC"

'Set the view to report
ListView1.View = lvwReport

Timer1.Interval = 1000 ' <-- 10 seconds
Timer1.Enabled = True

End Sub



Private Sub Timer1_Timer()
Dim lHrs As Long
Dim lMinutes As Long
Dim lSeconds As Long
'lSeconds = lSeconds + 1
lSeconds = 0 '<<<for this example purpose we Put 150 seconds
lSeconds = lSeconds + 1
lHrs = Int(lSeconds / 3600)
lMinutes = (Int(lSeconds / 60)) - (lHrs * 60)
lSeconds = Int(lSeconds Mod 60)

'yourresulthere = Format$(lHrs,"00") & ":" & Format$(lMinutes,"00") & ":" & Format$(lSeconds,"00")

ListView1.ListItems(1).ListSubItems(1).Text = Format$(lHrs, "00") & ":" & Format$(lMinutes, "00") & ":" & Format$(lSeconds, "00")
'MsgBox "test"

End Sub[/vb]
Last edited by method on Mon May 14, 2007 12:33 am, edited 1 time in total.
method
imFiles Master
imFiles Master
 
Posts: 686
Joined: Tue Oct 18, 2005 11:12 am

Postby BattleStar-Galactica » Mon May 14, 2007 1:15 am

delete this line >> lSeconds = 0 '<<<for this example purpose we Put 150 seconds


that line is just to initialize lSecond to 0. I see you put alway lSecond to 0 on timer function
Last edited by BattleStar-Galactica on Mon May 14, 2007 1:16 am, edited 1 time in total.
Big math problem
2 - 1 = 0 = without you I'm nothing
User avatar
BattleStar-Galactica
imFiles Master
imFiles Master
 
Posts: 565
Joined: Tue Sep 20, 2005 12:19 am
Location: safest place to hide

Postby autopilot » Mon May 14, 2007 1:50 pm

Please note: the example below is done in vb2005... may need slight mod to use in vb6

maybe try these as global dim:[vb] Dim hour As Integer = 0
Dim min As Integer = 0
Dim sec As Integer = 0
Dim s As String = "00"
Dim m As String = "00"
Dim h As String = "00"[/vb]
add timer to project and set it to enabled and an interval of 1000 (1 second) and then the following code for the timer:[vb]

sec += 1
Select Case sec
Case Is Less Than 10
s = "0" & sec.ToString
Case Is > 59
sec = 0
min += 1
s = "00"
Case Else
s = sec.ToString
End Select
Select Case min
Case Is < 10
m = "0" & min.ToString
Case Is Greater Than 59
min = 0
hour += 1
m = "00"
Case Else
m = min.ToString
End Select
Select Case hour
Case Is < 10
h = "0" & hour.ToString
Case Else
h = hour.ToString
End Select
ListView1.Items.Item(0).Text = String.Format("{00}:{01}:{02}", h, m, s)[/vb]

autopilot

EDIT: The <> were being read as xml code and changing the post... replace Less Than and Greater Than with apropriate symbol...
Attachments
Time Test.zip
vb2005 project
(114.67 KiB) Downloaded 72 times
Last edited by autopilot on Tue May 15, 2007 8:09 am, edited 5 times in total.
User avatar
autopilot
Forum Moderator
Forum Moderator
 
Posts: 358
Joined: Sat Sep 23, 2006 7:19 pm

Postby Ghost » Mon May 14, 2007 2:23 pm

YAYS FOR TEH VB TAG!

/me has nothing useful to contribute to this topic...
Ghost
 

Postby method » Mon May 14, 2007 3:14 pm

BattleStar-Galactica i comment out lSeconds =0 but timer never increments!!!

autopilot i wish i had visual basic 2005 edtion. So i don't know how to modify it for vb6!!!
Last edited by method on Mon May 14, 2007 3:16 pm, edited 2 times in total.
method
imFiles Master
imFiles Master
 
Posts: 686
Joined: Tue Oct 18, 2005 11:12 am

Next

Return to Visual Basic Programming

 


  • Related topics
    Replies
    Views
    Last post

Who is online

Users browsing this forum: No registered users and 0 guests