Skip to content

How to add clock timer to listview column ?

Viewing 15 posts - 1 through 15 (of 22 total)
  • Author
    Posts
  • #187906
    method
    Member

    could any one show me how i can add clock timer that shows hour:min:seconds to a perticuler listview column ?

    #187927

    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

    #187926
    method
    Member

    lol.What paint? could you show me a vb6 code?

    #187925
    sk8er
    Member

    listview1.text = time?

    #187924
    method
    Member

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

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

    #187923

    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

    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)

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

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

    [Ghost’s edit] OMG OMG OMG! USE TEH VB TAGS! THAT’S WHAT THEY’RE THERE FOR! [/Ghost’s edit]

    #187922
    method
    Member

    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 ?

    #187921

    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.

    #187920
    method
    Member

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

    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")

    I even placed a msgbox at the end timer and saw that timer is actually running but the timer is not!!

    #187919

    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

    #187918
    method
    Member

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

    Modul:

    Option Explicit
    'i am declaring varibles that be avalible every where

    Public lSeconds As Integer

    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
    #187917

    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

    #187916
    autopilot
    Member

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

    maybe try these as global dim:

        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"

    add timer to project and set it to enabled and an interval of 1000 (1 second) and then the following code for the timer:



    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)

    autopilot

    EDIT: The were being read as xml code and changing the post… replace Less Than and Greater Than with apropriate symbol…

    #187915
    Admin
    Administrator

    YAYS FOR TEH VB TAG!

    /me has nothing useful to contribute to this topic…

    #187914
    method
    Member

    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!!!

Viewing 15 posts - 1 through 15 (of 22 total)
  • You must be logged in to reply to this topic.