Results 1 to 38 of 38

Thread: [RESOLVED] Vb6: elapsed time + time in label1.caption

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2016
    Posts
    185

    Resolved [RESOLVED] Vb6: elapsed time + time in label1.caption

    Basically I need this:
    on form_load, start label1 counting how long since form1 loaded = this i already did it in the code bellow
    and i need 2 buttons, one to save current time running on label1 in textfile
    and second to add or load saved textfile into label1 and keep counting from there
    i hope you got my point
    here my code, plz help me out:
    ----------------
    Private mStartTime As Date

    Private Sub Form_Load()
    mStartTime = Now
    tmrDelta.Interval = 500
    End Sub

    Private Sub tmrDelta_Timer()
    Label1.Caption = "Started: " & GetElapsedTimeString(Now - mStartTime)
    End Sub

    Function GetElapsedTimeString(ByVal dT As Double) As String
    Const sFmt$ = " \d\a\y\s | h \h\o\u\r\s | m \m\i\n"
    GetElapsedTimeString = Int(dT) & Format$(dT, sFmt)
    End Function
    End Sub
    -----------
    Last edited by geekmaro; Jan 10th, 2021 at 11:45 PM.

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Mar 2016
    Posts
    185

    Re: Vb6: elapsed time + time in label1.caption

    help plz
    Last edited by geekmaro; Jan 10th, 2021 at 11:29 PM.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2016
    Posts
    185

    Re: Vb6: elapsed time + time in label1.caption

    anyone ?
    Last edited by geekmaro; Jan 10th, 2021 at 11:30 PM.

  4. #4
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    13,382

    Re: Vb6: elapsed time + time in label1.caption

    So you are asking how to do a simple file read/write?
    You can use the basic Open statement. It doesn't matter what you are trying to read or write, text is text so same methods as any simple text file.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Mar 2016
    Posts
    185

    Re: Vb6: elapsed time + time in label1.caption

    Quote Originally Posted by DataMiser View Post
    So you are asking how to do a simple file read/write?
    You can use the basic Open statement. It doesn't matter what you are trying to read or write, text is text so same methods as any simple text file.
    no, you didnt understand what im trying to do
    I want to count elapsed time from saved textfile
    you can read again what i asked for and im sure you will understand

  6. #6
    New Member
    Join Date
    May 2020
    Posts
    11

    Re: Vb6: elapsed time + time in label1.caption

    Hi,
    i thing i got what are you trying to accomplish ,
    try to add the class Stopwatch

    'class
    Option Explicit

    Private Declare Function QueryPerformanceCounter Lib "kernel32" (X As Currency) As Boolean
    Private Declare Function QueryPerformanceFrequency Lib "kernel32" (X As Currency) As Boolean

    Private m_startTime As Currency
    Private m_freq As Currency
    Private m_overhead As Currency

    Public Sub start()
    10 QueryPerformanceCounter m_startTime
    End Sub

    Public Function ElapsedSeconds() As Double
    Dim currentTime As Currency
    10 QueryPerformanceCounter currentTime
    20 ElapsedSeconds = (currentTime - m_startTime - m_overhead) / m_freq
    End Function

    Public Function ElapsedMilliseconds() As Double
    10 ElapsedMilliseconds = ElapsedSeconds * 1000
    End Function

    Private Sub Class_Initialize()
    10 QueryPerformanceFrequency m_freq
    Dim ctr1 As Currency
    Dim ctr2 As Currency
    20 QueryPerformanceCounter ctr1
    30 QueryPerformanceCounter ctr2
    40 m_overhead = ctr2 - ctr1
    End Sub


    then in your form
    Dim sw As STOPWATCH
    10 Set sw = New STOPWATCH
    20 sw.start
    'do some stuff here to let the time moves...
    100 msgbox sw.ElapsedMilliseconds
    there you have the time elapsed ...

  7. #7
    Frenzied Member
    Join Date
    Dec 2014
    Posts
    1,364

    Re: Vb6: elapsed time + time in label1.caption

    load/save as DataMiser posted is what u need.
    just use binary get/put and load/save mStartTime

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Mar 2016
    Posts
    185

    Re: Vb6: elapsed time + time in label1.caption

    Quote Originally Posted by baka View Post
    load/save as DataMiser posted is what u need.
    just use binary get/put and load/save mStartTime
    could you plz post code ?
    im newbie i dont know how to write that code
    thanx in advance

  9. #9
    Frenzied Member
    Join Date
    Dec 2014
    Posts
    1,364

    Re: Vb6: elapsed time + time in label1.caption

    Code:
    Private mStartTime As Date
    
    Private Sub Command1_Click()
        Open App.Path & "\time.data" For Binary As #1
            Put #1, , mStartTime
        Close #1
    End Sub
    
    Private Sub Command2_Click()
        Open App.Path & "\time.data" For Binary As #1
            Get #1, , mStartTime
        Close #1
    End Sub
    
    Private Sub Form_Load()
    mStartTime = Now
    tmrDelta.Interval = 500
    End Sub
    
    Private Sub tmrDelta_Timer()
    Label1.Caption = "Started: " & GetElapsedTimeString(Now - mStartTime)
    End Sub
    
    Function GetElapsedTimeString(ByVal dT As Double) As String
    Const sFmt$ = " \d\a\y\s | h \h\o\u\r\s | m \m\i\n | s \s\e\c\o\n\d\s"
    GetElapsedTimeString = Int(dT) & Format$(dT, sFmt)
    End Function
    when u click Command1 it will save the current time. u can now close the program.
    when u open the program again, u will notice it will start over, but if u use Command2 it will take the old starting time and continue from there. (added seconds, just to see the result, dont want to wait minutes for the testing)

  10. #10
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    7,705

    Re: Vb6: elapsed time + time in label1.caption

    This is what DM meant:

    Code:
    Option ExplicitDim inFile As String
    Dim outFile As String
    Private mStartTime As Date
    
    
    Private Sub Command1_Click()
        outFile = FreeFile
        Open "Path and filename here" For Output As #outFile
        Print #outFile, Label1.Caption
        Close #outFile
    End Sub
    
    
    Private Sub Command2_Click()
        Dim myLine As String
        inFile = FreeFile
        Open "Path and filename here" For Input As #inFile
        Line Input #inFile, myLine
        Label1.Caption = myLine
        mStartTime = Now  'Reset Start Time
        Close #inFile
    End Sub
    
    
    Private Sub Form_Load()
        mStartTime = Now
        tmrDelta.Interval = 500
    End Sub
    
    
    Private Sub tmrDelta_Timer()
        Label1.Caption = "Started: " & GetElapsedTimeString(Now - mStartTime)
    End Sub
    
    
    Function GetElapsedTimeString(ByVal dT As Double) As String
        Const sFmt$ = " \d\a\y\s | h \h\o\u\r\s | m \m\i\n"
        GetElapsedTimeString = Int(dT) & Format$(dT, sFmt)
    End Function
    Sam I am (as well as Confused at times).

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Mar 2016
    Posts
    185

    Re: Vb6: elapsed time + time in label1.caption

    Quote Originally Posted by SamOscarBrown View Post
    This is what DM meant:

    Code:
    Option ExplicitDim inFile As String
    Dim outFile As String
    Private mStartTime As Date
    
    
    Private Sub Command1_Click()
        outFile = FreeFile
        Open "Path and filename here" For Output As #outFile
        Print #outFile, Label1.Caption
        Close #outFile
    End Sub
    
    
    Private Sub Command2_Click()
        Dim myLine As String
        inFile = FreeFile
        Open "Path and filename here" For Input As #inFile
        Line Input #inFile, myLine
        Label1.Caption = myLine
        mStartTime = Now  'Reset Start Time
        Close #inFile
    End Sub
    
    
    Private Sub Form_Load()
        mStartTime = Now
        tmrDelta.Interval = 500
    End Sub
    
    
    Private Sub tmrDelta_Timer()
        Label1.Caption = "Started: " & GetElapsedTimeString(Now - mStartTime)
    End Sub
    
    
    Function GetElapsedTimeString(ByVal dT As Double) As String
        Const sFmt$ = " \d\a\y\s | h \h\o\u\r\s | m \m\i\n"
        GetElapsedTimeString = Int(dT) & Format$(dT, sFmt)
    End Function
    i m having a problem with command2, it loads the time from textfile but immediately goes back to Started: 0 days | 0 hours | 0 min
    how to fix it ?

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Mar 2016
    Posts
    185

    Re: Vb6: elapsed time + time in label1.caption

    Quote Originally Posted by baka View Post
    Code:
    Private mStartTime As Date
    
    Private Sub Command1_Click()
        Open App.Path & "\time.data" For Binary As #1
            Put #1, , mStartTime
        Close #1
    End Sub
    
    Private Sub Command2_Click()
        Open App.Path & "\time.data" For Binary As #1
            Get #1, , mStartTime
        Close #1
    End Sub
    
    Private Sub Form_Load()
    mStartTime = Now
    tmrDelta.Interval = 500
    End Sub
    
    Private Sub tmrDelta_Timer()
    Label1.Caption = "Started: " & GetElapsedTimeString(Now - mStartTime)
    End Sub
    
    Function GetElapsedTimeString(ByVal dT As Double) As String
    Const sFmt$ = " \d\a\y\s | h \h\o\u\r\s | m \m\i\n | s \s\e\c\o\n\d\s"
    GetElapsedTimeString = Int(dT) & Format$(dT, sFmt)
    End Function
    when u click Command1 it will save the current time. u can now close the program.
    when u open the program again, u will notice it will start over, but if u use Command2 it will take the old starting time and continue from there. (added seconds, just to see the result, dont want to wait minutes for the testing)
    it works but i need to save label1 time with text1.text in textfile and load it and get second line of textfile which is the saved time to label1
    Open App.Path & "\1.txt" For Output As #1
    Print #1, Text1.Text
    Put #1, , mStartTime = it says bad file mode
    Close #1

    plz help
    Last edited by geekmaro; Jan 11th, 2021 at 10:40 AM.

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Mar 2016
    Posts
    185

    Re: Vb6: elapsed time + time in label1.caption

    so far i was able to save label1 + text1 into textfile using this code:
    ----
    Open App.Path & "\1.txt" For Binary As #1
    Put #1, , Text1.Text & vbCrLf
    Put #1, , mStartTime
    Close #1
    --
    but now i need to load only second line from textfile into label1
    i tried this but not working
    ----
    Dim line1 As String, line2 As String
    Open App.Path & "\1.txt" For Binary As #1
    Line Input #1, line2
    Get #1, , mStartTime = line2
    Close #1

  14. #14
    Frenzied Member
    Join Date
    Dec 2014
    Posts
    1,364

    Re: Vb6: elapsed time + time in label1.caption

    u can't use Get/Put with Input/OutPut. Get/Put is for Binary Access.
    just replace Put with Print #1, mStartTime

    don't mix the 2 modes.

    so use Print #1 and Input #1 and nothing else.

  15. #15

    Thread Starter
    Addicted Member
    Join Date
    Mar 2016
    Posts
    185

    Re: Vb6: elapsed time + time in label1.caption

    Quote Originally Posted by baka View Post
    u can't use Get/Put with Input/OutPut. Get/Put is for Binary Access.
    just replace Put with Print #1, mStartTime

    don't mix the 2 modes.
    sorry i didnt understand you
    could you plz give me full code so i can try it and let you know result ?

  16. #16
    Frenzied Member
    Join Date
    Dec 2014
    Posts
    1,364

    Re: Vb6: elapsed time + time in label1.caption

    this is a home assignment as I suspect it.

    should clicking on the save button, save the current time on that text-file, maybe u need to use Append as well?
    it seems that u need:

    1. click on "save" to store the current time on a text-file, each time you do that it will add a new time on the text-file
    2. click on "load" will take the "last" time and continue counting.

    that means, u need to use eof(1) and Append.

  17. #17

    Thread Starter
    Addicted Member
    Join Date
    Mar 2016
    Posts
    185

    Re: Vb6: elapsed time + time in label1.caption

    Quote Originally Posted by baka View Post
    this is a home assignment as I suspect it.

    should clicking on the save button, save the current time on that text-file, maybe u need to use Append as well?
    it seems that u need:

    1. click on "save" to store the current time on a text-file, each time you do that it will add a new time on the text-file
    2. click on "load" will take the "last" time and continue counting.

    that means, u need to use eof(1) and Append.
    exactly now you understand what i need, but i have to save text1.text as first line in textfile, and label1.caption as second line in same textfile
    then when load, get last time and continue counting from second line in textfile, so you need to skip first line.
    hope all clear
    plz give me the code
    thanx alot for your help

  18. #18
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    7,705

    Re: Vb6: elapsed time + time in label1.caption

    Quote Originally Posted by geekmaro View Post
    i m having a problem with command2, it loads the time from textfile but immediately goes back to Started: 0 days | 0 hours | 0 min
    how to fix it ?
    Oh yes,....sorry....just a moment
    Sam I am (as well as Confused at times).

  19. #19
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    7,705

    Re: Vb6: elapsed time + time in label1.caption

    I just hacked this together real quickly...I save THREE things in your text file: Text1.Text, Label1.Caption and Label2.Caption (I put a in invisible label2 on the form and set its value to NOW---you can do the same by using a variable to save "NOW").

    Notice I read the THIRD line in the file! IOW, you really don't need the second line (label1.caption) at all...if you opt not to include it in the file, simply delete one of the 'Line Input' calls.

    Hope this works for you:

    Code:
    Option ExplicitDim inFile As String
    Dim outFile As String
    Dim newTime As Date
    Dim bRestart As Boolean
    Private mStartTime As Date
    
    
    Private Sub Command1_Click()
        outFile = FreeFile
        Open "C:\users\denni\time.txt" For Output As #outFile
        Print #outFile, Text1.Text
        Print #outFile, Label1.Caption
        Print #outFile, Now
        Close #outFile
    End Sub
    
    
    Private Sub Command2_Click()
        Dim myLine As String
        inFile = FreeFile
        Open "C:\users\denni\time.txt" For Input As #inFile
        Line Input #inFile, myLine
        Line Input #inFile, myLine
        Line Input #inFile, myLine
        Label2.Caption = myLine
        newTime = CDate(myLine)
        bRestart = True
        Close #inFile
    End Sub
    
    
    Private Sub Form_Load()
        mStartTime = Now
        tmrDelta.Interval = 500
        Label2.Caption = CStr(Now)
    End Sub
    
    
    Private Sub tmrDelta_Timer()
        If bRestart = False Then
            Label1.Caption = "Started: " & GetElapsedTimeString(Now - mStartTime)
        Else
            Label1.Caption = "Started: " & GetElapsedTimeString(Now - newTime)
        End If
    End Sub
    
    
    Function GetElapsedTimeString(ByVal dT As Double) As String
        Const sFmt$ = " \d\a\y\s | h \h\o\u\r\s | m \m\i\n"
        GetElapsedTimeString = Int(dT) & Format$(dT, sFmt)
        Label2.Caption = CStr(Now)
    End Function
    Sam I am (as well as Confused at times).

  20. #20
    Frenzied Member
    Join Date
    Nov 2017
    Posts
    1,388

    Re: Vb6: elapsed time + time in label1.caption

    Quote Originally Posted by geekmaro View Post
    could you plz post code ?
    im newbie i dont know how to write that code
    thanx in advance
    You've been a member here for almost 5 years. Do you have intentions on learning to write code yourself?

  21. #21

    Thread Starter
    Addicted Member
    Join Date
    Mar 2016
    Posts
    185

    Re: Vb6: elapsed time + time in label1.caption

    Quote Originally Posted by SamOscarBrown View Post
    I just hacked this together real quickly...I save THREE things in your text file: Text1.Text, Label1.Caption and Label2.Caption (I put a in invisible label2 on the form and set its value to NOW---you can do the same by using a variable to save "NOW").

    Notice I read the THIRD line in the file! IOW, you really don't need the second line (label1.caption) at all...if you opt not to include it in the file, simply delete one of the 'Line Input' calls.

    Hope this works for you:

    Code:
    Option ExplicitDim inFile As String
    Dim outFile As String
    Dim newTime As Date
    Dim bRestart As Boolean
    Private mStartTime As Date
    
    
    Private Sub Command1_Click()
        outFile = FreeFile
        Open "C:\users\denni\time.txt" For Output As #outFile
        Print #outFile, Text1.Text
        Print #outFile, Label1.Caption
        Print #outFile, Now
        Close #outFile
    End Sub
    
    
    Private Sub Command2_Click()
        Dim myLine As String
        inFile = FreeFile
        Open "C:\users\denni\time.txt" For Input As #inFile
        Line Input #inFile, myLine
        Line Input #inFile, myLine
        Line Input #inFile, myLine
        Label2.Caption = myLine
        newTime = CDate(myLine)
        bRestart = True
        Close #inFile
    End Sub
    
    
    Private Sub Form_Load()
        mStartTime = Now
        tmrDelta.Interval = 500
        Label2.Caption = CStr(Now)
    End Sub
    
    
    Private Sub tmrDelta_Timer()
        If bRestart = False Then
            Label1.Caption = "Started: " & GetElapsedTimeString(Now - mStartTime)
        Else
            Label1.Caption = "Started: " & GetElapsedTimeString(Now - newTime)
        End If
    End Sub
    
    
    Function GetElapsedTimeString(ByVal dT As Double) As String
        Const sFmt$ = " \d\a\y\s | h \h\o\u\r\s | m \m\i\n"
        GetElapsedTimeString = Int(dT) & Format$(dT, sFmt)
        Label2.Caption = CStr(Now)
    End Function
    this is what i got when i saved textfile:
    ----
    Text1
    Started: 0 days | 0 hours | 6 min
    1/11/2021 12:00:23 PM
    -----
    but when i click command2, nothing happened to label1

  22. #22
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    7,705

    Re: Vb6: elapsed time + time in label1.caption

    Really? With that code label1 changes to the time (minute) set in the textfile, and then the counter starts from THAT time and every minute more it will change.

    Are you using all this code, and in conjunction with YOUR project? If so, start a NEW project, add a text box, two labels and two command buttons and run it (name your timer as tmrDelta, leave all the rest as default).

    Works fine for me.
    Attached Files Attached Files
    Sam I am (as well as Confused at times).

  23. #23

    Thread Starter
    Addicted Member
    Join Date
    Mar 2016
    Posts
    185

    Re: Vb6: elapsed time + time in label1.caption

    Quote Originally Posted by SamOscarBrown View Post
    Really? With that code label1 changes to the time (minute) set in the textfile, and then the counter starts from THAT time and every minute more it will change.

    Are you using all this code, and in conjunction with YOUR project? If so, start a NEW project, add a text box, two labels and two command buttons and run it (name your timer as tmrDelta, leave all the rest as default).

    Works fine for me.
    i download your project and tested it
    when i click command1, i get this inside textfile:
    ---
    SAM
    Started: 0 days | 0 hours | 8 min
    1/11/2021 12:38:09 PM
    ----
    then when i closed form1 and run it again i got this:
    label1 = Started: 0 days | 0 hours | 1 min
    it should show: Started: 0 days | 0 hours | 8 min and continue counting from the moment i clicked command2
    you got it now ?

  24. #24
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    7,705

    Re: Vb6: elapsed time + time in label1.caption

    You didn't say anything about Closing the Form....of course it is going to revert. So, I misunderstood what your intent was....
    Sam I am (as well as Confused at times).

  25. #25

    Thread Starter
    Addicted Member
    Join Date
    Mar 2016
    Posts
    185

    Re: Vb6: elapsed time + time in label1.caption

    Quote Originally Posted by SamOscarBrown View Post
    You didn't say anything about Closing the Form....of course it is going to revert. So, I misunderstood what your intent was....
    sorry about that, plz help me out buddy

  26. #26
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    7,705

    Re: Vb6: elapsed time + time in label1.caption

    May get to it tomorrow morning..busy ROT.

    Think about it, though. Maybe you can do it yourself now that you know how to save and read files...
    The first time your program is run you need to have all zeros in your label, which means you set some variable to NOW.
    All future times the program is run, you should read the last saved file and start with that date/time (that's why I used a second label to capture date/time instead of a string).
    One way to do it is in the first time the program is run, start your program like you did originally (mStartTime = Now), but after that, your mStartTime should be taken from the file and compared to NOW.

    Another way to do this is to use a database table...much easier to understand than reading/writing text files.

    If I find time in the morning, I'll crank up something...but I am sure others can assist before then.

    Sammi
    Sam I am (as well as Confused at times).

  27. #27

    Thread Starter
    Addicted Member
    Join Date
    Mar 2016
    Posts
    185

    Re: Vb6: elapsed time + time in label1.caption

    Quote Originally Posted by SamOscarBrown View Post
    May get to it tomorrow morning..busy ROT.

    Think about it, though. Maybe you can do it yourself now that you know how to save and read files...
    The first time your program is run you need to have all zeros in your label, which means you set some variable to NOW.
    All future times the program is run, you should read the last saved file and start with that date/time (that's why I used a second label to capture date/time instead of a string).
    One way to do it is in the first time the program is run, start your program like you did originally (mStartTime = Now), but after that, your mStartTime should be taken from the file and compared to NOW.

    Another way to do this is to use a database table...much easier to understand than reading/writing text files.

    If I find time in the morning, I'll crank up something...but I am sure others can assist before then.

    Sammi
    well i will wait for you and for others

  28. #28
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    7,705

    Re: Vb6: elapsed time + time in label1.caption

    I THINK what you are after is a label telling you how many minutes the program has been run, including subsequent runs.
    Meaning, at first go it runs, for example, 4 minutes, then the user quits the program. Next time the program is started, you want to have those
    4 minutes as the starting point, so that you will know how many minutes the program has been run total time. At least I THINK this is your goal.

    If so, I am working up a small example using a database to keep track of total time it is being run.

    BUT, may not be for a bit...lot to do tomorrow.
    Sam I am (as well as Confused at times).

  29. #29

    Thread Starter
    Addicted Member
    Join Date
    Mar 2016
    Posts
    185

    Re: Vb6: elapsed time + time in label1.caption

    Quote Originally Posted by SamOscarBrown View Post
    I THINK what you are after is a label telling you how many minutes the program has been run, including subsequent runs.
    Meaning, at first go it runs, for example, 4 minutes, then the user quits the program. Next time the program is started, you want to have those
    4 minutes as the starting point, so that you will know how many minutes the program has been run total time. At least I THINK this is your goal.

    If so, I am working up a small example using a database to keep track of total time it is being run.

    BUT, may not be for a bit...lot to do tomorrow.
    now you understand my point
    i dont think you need database, i just need to save label1 value into textfile along with text1.text
    and load it again
    no need to complicate things
    and think about saving and loading for text1 as well
    i can wait till tomorrow
    no prob. thanx

  30. #30

    Thread Starter
    Addicted Member
    Join Date
    Mar 2016
    Posts
    185

    Re: Vb6: elapsed time + time in label1.caption

    guys anyone ? i need to finish this project asap..

  31. #31
    Frenzied Member
    Join Date
    Dec 2014
    Posts
    1,364

    Re: Vb6: elapsed time + time in label1.caption

    are u incapable of trying yourself?
    u know how to load and save, just do some trial and errors with that until u get it right.

  32. #32

    Thread Starter
    Addicted Member
    Join Date
    Mar 2016
    Posts
    185

    Re: Vb6: elapsed time + time in label1.caption

    Quote Originally Posted by baka View Post
    are u incapable of trying yourself?
    u know how to load and save, just do some trial and errors with that until u get it right.
    this too hard for me, i tried alot but could not do it

  33. #33
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    7,705

    Re: Vb6: elapsed time + time in label1.caption

    Ok, so this is what I did...one textbox, one label, one "Exit" button (the exit button saves the new runtime to the textfile).

    You can experiment by editing the text file...currently it is at:

    SAMMI
    0
    (The zero represent the total runtime--will change if you run the program for at least one minute)
    That 0 will change when you exit the program (will increase by the number of minutes the program has been run), and will be loaded next time at form_load). Put in a larger number if you want to test to see # of days and hours and minutes how they change.

    If you find an error (or it is not exactly what you want), let me know.

    Sammi
    Attached Files Attached Files
    Sam I am (as well as Confused at times).

  34. #34

    Thread Starter
    Addicted Member
    Join Date
    Mar 2016
    Posts
    185

    Re: Vb6: elapsed time + time in label1.caption

    Quote Originally Posted by SamOscarBrown View Post
    Ok, so this is what I did...one textbox, one label, one "Exit" button (the exit button saves the new runtime to the textfile).

    You can experiment by editing the text file...currently it is at:


    (The zero represent the total runtime--will change if you run the program for at least one minute)
    That 0 will change when you exit the program (will increase by the number of minutes the program has been run), and will be loaded next time at form_load). Put in a larger number if you want to test to see # of days and hours and minutes how they change.

    If you find an error (or it is not exactly what you want), let me know.

    Sammi
    Right here at form load, i need to load text1.text as well, the way you did it getting the 2nd line for label1 i dont like it, i wana something simpler like this:

    Dim line1 As String, line2 As String, line3 As String, line4 As String, line5 As String, line6 As String, line7 As String, line8 As String

    Open App.Path & "\1.txt" For Input As #1
    Line Input #1, line1
    Line Input #1, line2
    Close #1

    Text1.Text = line1
    Label1.Caption = line2

    could you implement something like this resend me project?
    thanks alot

  35. #35
    Frenzied Member
    Join Date
    Dec 2014
    Posts
    1,364

    Re: Vb6: elapsed time + time in label1.caption

    Code:
    Private mStartTime As Date
    
    Private Sub Command1_Click()
        Open App.Path & "\time.txt" For Output As #1
            Print #1, Text1.Text
            Print #1, mStartTime
        Close #1
    End Sub
    
    Private Sub Command2_Click()
        Dim Data$
    
        Open App.Path & "\time.txt" For Input As #1
            Line Input #1, Data
            Text1.Text = Data
            Line Input #1, Data
            mStartTime = Data
        Close #1
    End Sub
    
    Private Sub Form_Load()
    mStartTime = Now
    tmrDelta.Interval = 500
    End Sub
    
    Private Sub tmrDelta_Timer()
    Label1.Caption = "Started: " & GetElapsedTimeString(Now - mStartTime)
    End Sub
    
    Function GetElapsedTimeString(ByVal dT As Double) As String
    Const sFmt$ = " \d\a\y\s | h \h\o\u\r\s | m \m\i\n | s \s\e\c\o\n\d\s"
    GetElapsedTimeString = Int(dT) & Format$(dT, sFmt)
    End Function

  36. #36
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    7,705

    Re: Vb6: elapsed time + time in label1.caption

    geez...I give up....it is as simple as it can be....it puts in TWO lines, text1.text and the total runtime.

    So, I am done.

    Off this thread.

    Oh, and 'you're welcome'
    Sam I am (as well as Confused at times).

  37. #37

    Thread Starter
    Addicted Member
    Join Date
    Mar 2016
    Posts
    185

    Re: Vb6: elapsed time + time in label1.caption

    Quote Originally Posted by SamOscarBrown View Post
    geez...I give up....it is as simple as it can be....it puts in TWO lines, text1.text and the total runtime.

    So, I am done.

    Off this thread.

    Oh, and 'you're welcome'
    plz help me out this code:
    Private Sub Form_Load()
    tmrDelta.Interval = 1000
    Dim myLine As String
    inFile = FreeFile
    Open App.Path & "\time.txt" For Input As #inFile
    Line Input #inFile, myLine
    Line Input #inFile, myLine
    savedMinutes = CLng(myLine)
    convertMinutesToHoursAndDays (savedMinutes)
    tmrDelta.Enabled = True
    Close #inFile
    End Sub
    i need to make it simpler
    load text1 + time into label1

  38. #38

    Thread Starter
    Addicted Member
    Join Date
    Mar 2016
    Posts
    185

    Re: Vb6: elapsed time + time in label1.caption

    Quote Originally Posted by SamOscarBrown View Post
    geez...I give up....it is as simple as it can be....it puts in TWO lines, text1.text and the total runtime.

    So, I am done.

    Off this thread.

    Oh, and 'you're welcome'
    I made it work, thanks for your help

    Private Sub Form_Load()
    Dim line1 As String, line2 As String
    tmrDelta.Interval = 1000
    inFile = FreeFile
    Open App.Path & "\time.txt" For Input As #inFile
    Line Input #inFile, line1
    Line Input #inFile, line2
    Text1.Text = line1
    savedMinutes = CLng(line2)
    convertMinutesToHoursAndDays (savedMinutes)
    tmrDelta.Enabled = True
    Close #inFile
    End Sub

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width