locked
Actualization of time in clock and timers after restart - problem RRS feed

  • Question

  • Like in topic. I have big problem with my code, which have to actualize time and timers in program after run. Main clock works on another calendar and time then real calendar (Details - http://wurmpedia.com/index.php/Time). Code is working, but it ALWAYS sets the time for a few days, hours, minutes and seconds forward. Maybe there is easier method to do what I want? If you want to see how a problem in practice - program is nearly ready, link do download: https://dl.dropbox.com/u/67758055/Wu...%20problem.zip.

    After download and run you have to enter tools tab and then Wurm Online Calendar - to see this error you have to close program (when you try to close program it will minimalize to tray, "exit" option appears on RMB click on icon) and run again.

    If this is necessary, I can send the whole tool code.

    Code that save actual time:

        Private Sub Timer4_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer4.Tick
            Dim currenttime As String = TimeOfDay.ToString
            My.Settings.currentsec = currenttime.Substring(6, 2)
            My.Settings.currentmin = currenttime.Substring(3, 2)
            My.Settings.currenthour = currenttime.Substring(0, 2)
            My.Settings.currentdate = Today
            My.Settings.universalday = ((My.Settings.wurmmonth * 28) - 28) + ((My.Settings.wurmweek * 7) - 7) + My.Settings.wurmday
            My.Settings.Save()
        End Sub

    Fragment of code before form load (directly on class):

        'synchronization variables'
    
        Dim lauchdate As Date = Today
        Dim launchtime As String = TimeOfDay
        Dim launchsec As Short = launchtime.Substring(6, 2)
        Dim launchmin As Short = launchtime.Substring(3, 2)
        Dim launchhour As Short = launchtime.Substring(0, 2)
        Dim betweendates As Long = DateDiff(DateInterval.Day, lauchdate, My.Settings.currentdate)
        Dim launchtotaltime As Long = (betweendates * 86400) + (launchhour * 3600) + (launchmin * 60) + launchsec
        Dim currenttotaltime As Long = (My.Settings.currenthour * 3600) + (My.Settings.currentmin * 60) + My.Settings.currentsec
        Dim totaltime As Long = launchtotaltime - currenttotaltime
    
        Dim wurmClockTotalTime As Long = totaltime * 8
        Dim restartTotalTime As Long = totaltime
        Dim prayTotalTime As Long = totaltime
        Dim meditationTotalTime As Long = totaltime


    Main actualization code, on form load:

        Sub timeguard(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            If wurmClockTotalTime >= 29030400 Then
                Dim awurmClockYear As Double = wurmClockTotalTime / 29030400
                Dim wurmClockYear As Double = Math.Floor(awurmClockYear)
                wurmClockTotalTime = wurmClockTotalTime - (wurmClockYear * 29030400)
            End If
            If wurmClockTotalTime >= 2419200 Then
                Dim awurmClockMonth As Double = wurmClockTotalTime / 2419200
                Dim wurmClockMonth As Double = Math.Floor(awurmClockMonth)
                My.Settings.wurmmonth = My.Settings.wurmmonth + wurmClockMonth
                wurmClockTotalTime = wurmClockTotalTime - (wurmClockMonth * 2419200)
            End If
            If wurmClockTotalTime >= 604800 Then
                Dim awurmClockWeek As Double = wurmClockTotalTime / 604800
                Dim wurmClockWeek As Double = Math.Floor(awurmClockWeek)
                My.Settings.wurmweek = My.Settings.wurmweek + wurmClockWeek
                wurmClockTotalTime = wurmClockTotalTime - (wurmClockWeek * 604800)
            End If
            If wurmClockTotalTime >= 86400 Then
                Dim awurmClockDay As Double = wurmClockTotalTime / 86400
                Dim wurmClockDay As Double = Math.Floor(awurmClockDay)
                My.Settings.wurmday = My.Settings.wurmday + wurmClockDay
                wurmClockTotalTime = wurmClockTotalTime - (wurmClockDay * 86400)
            End If
            If wurmClockTotalTime >= 3600 Then
                Dim awurmClockHour As Double = wurmClockTotalTime / 3600
                Dim wurmClockHour As Double = Math.Floor(awurmClockHour)
                My.Settings.wurmhour = My.Settings.wurmhour + wurmClockHour
                wurmClockTotalTime = wurmClockTotalTime - (wurmClockHour * 3600)
            End If
            If wurmClockTotalTime >= 60 Then
                Dim awurmClockMin As Double = wurmClockTotalTime / 60
                Dim wurmClockMin As Double = Math.Floor(awurmClockMin)
                My.Settings.wurmmin = My.Settings.wurmmin + wurmClockMin
                wurmClockTotalTime = wurmClockTotalTime - (wurmClockMin * 60)
            End If
            If wurmClockTotalTime >= 1 Then
                Dim wurmClockSec As Double = wurmClockTotalTime
                My.Settings.wurmsec = My.Settings.wurmsec + wurmClockSec
                wurmClockTotalTime = wurmClockTotalTime - wurmClockSec
            End If
            If My.Settings.wurmsec >= 60 Then
                Dim amin As Double = My.Settings.wurmsec / 60
                Dim min As Double = Math.Floor(amin)
                My.Settings.wurmmin = My.Settings.wurmmin + min
                My.Settings.wurmsec = My.Settings.wurmsec - (min * 60)
            End If
            If My.Settings.wurmmin >= 60 Then
                Dim ahour As Double = My.Settings.wurmmin / 60
                Dim hour As Double = Math.Floor(ahour)
                My.Settings.wurmhour = My.Settings.wurmhour + hour
                My.Settings.wurmmin = My.Settings.wurmmin - (hour * 60)
            End If
            If My.Settings.wurmhour >= 24 Then
                Dim aday As Double = My.Settings.wurmhour / 24
                Dim day As Double = Math.Floor(aday)
                My.Settings.wurmday = My.Settings.wurmday + day
                My.Settings.wurmhour = My.Settings.wurmhour - (day * 24)
            End If
            If My.Settings.wurmday >= 8 Then
                Dim aweek As Double = My.Settings.wurmday / 7
                Dim week As Double = Math.Floor(aweek)
                My.Settings.wurmweek = My.Settings.wurmweek + week
                My.Settings.wurmday = My.Settings.wurmday - (week * 7)
            End If
            If My.Settings.wurmweek >= 5 Then
                Dim amonth As Double = My.Settings.wurmweek / 4
                Dim month As Double = Math.Floor(amonth)
                My.Settings.wurmmonth = My.Settings.wurmmonth + month
                My.Settings.wurmweek = My.Settings.wurmweek - (month * 4)
            End If
            If My.Settings.wurmmonth >= 13 Then
                Dim ayear As Double = My.Settings.wurmweek / 12
                Dim year As Double = Math.Floor(ayear)
                My.Settings.wurmmonth = My.Settings.wurmweek - (year * 12)
            End If
    
            If restartTotalTime >= 86400 Then
                Dim arestartTimeDay As Double = restartTotalTime / 86400
                Dim restartTimeDay As Double = Math.Floor(arestartTimeDay)
                restartTotalTime = restartTotalTime - (restartTimeDay * 86400)
            End If
            If restartTotalTime >= 3600 Then
                Dim arestartTimeHour As Double = restartTotalTime / 3600
                Dim restartTimeHour As Double = Math.Floor(arestartTimeHour)
                My.Settings.restarthour = My.Settings.restarthour + restartTimeHour
                restartTotalTime = restartTotalTime - (restartTimeHour * 3600)
            End If
            If restartTotalTime >= 60 Then
                Dim arestartTimeMin As Double = restartTotalTime / 60
                Dim restartTimeMin As Double = Math.Floor(arestartTimeMin)
                My.Settings.restartmin = My.Settings.restartmin + restartTimeMin
                restartTotalTime = restartTotalTime - (restartTimeMin * 60)
            End If
            If restartTotalTime >= 60 Then
                Dim restartTimeSec As Double = restartTotalTime
                My.Settings.restartsec = My.Settings.restartsec + restartTimeSec
                restartTotalTime = restartTotalTime - (restartTimeSec)
            End If
            If My.Settings.restartsec >= 60 Then
                Dim amin As Double = My.Settings.restartsec / 60
                Dim min As Double = Math.Floor(amin)
                My.Settings.restartmin = My.Settings.restartmin + min
                My.Settings.restartsec = My.Settings.restartsec - (min * 60)
            End If
            If My.Settings.restartmin >= 60 Then
                Dim ahour As Double = My.Settings.restartmin / 60
                Dim hour As Double = Math.Floor(ahour)
                My.Settings.restarthour = My.Settings.restarthour + hour
                My.Settings.restartmin = My.Settings.restartmin - (hour * 60)
            End If
            If My.Settings.restarthour >= 24 Then
                Dim aday As Double = My.Settings.restarthour / 24
                Dim day As Double = Math.Floor(aday)
                My.Settings.restarthour = My.Settings.restarthour - (day * 24)
            End If
    
            If My.Settings.prays < 5 Then
                If My.Settings.praynow = True Then
                    If prayTotalTime >= ((My.Settings.praymin * 60) + My.Settings.praysec) Then
                        NumericUpDown1.Enabled = True
                        My.Settings.praynow = False
                        My.Settings.praymin = 0
                        My.Settings.praysec = 0
                        Button5.Enabled = True
                    ElseIf prayTotalTime < ((My.Settings.praymin * 60) + My.Settings.praysec) Then
                        Dim apraymin As Double = prayTotalTime / 60
                        Dim praymin As Double = Math.Floor(apraymin)
                        My.Settings.praymin = My.Settings.praymin + praymin
                        prayTotalTime = prayTotalTime - (praymin * 60)
                        My.Settings.praysec = My.Settings.praysec + prayTotalTime
                        Button5.Enabled = False
                        NumericUpDown1.Enabled = False
                    End If
                End If
            End If
            If My.Settings.praysec >= 60 Then
                Dim amin As Double = My.Settings.praysec / 60
                Dim min As Double = Math.Floor(amin)
                My.Settings.praymin = My.Settings.praymin + min
                My.Settings.praysec = My.Settings.praysec - (min * 60)
            End If
            If My.Settings.praymin >= 60 Then
                Dim ahour As Double = My.Settings.praymin / 60
                Dim hour As Double = Math.Floor(ahour)
                My.Settings.praymin = My.Settings.praymin - (hour * 60)
            End If
    
            If My.Settings.meditatenow = True Then
                If meditationTotalTime >= ((My.Settings.meditatehour * 3600) + (My.Settings.meditatemin * 60) + My.Settings.meditatesec) Then
                    NumericUpDown2.Enabled = True
                    My.Settings.meditatenow = False
                    My.Settings.meditatehour = 0
                    My.Settings.meditatemin = 0
                    My.Settings.meditatesec = 0
                    Button8.Enabled = True
                ElseIf meditationTotalTime < ((My.Settings.meditatehour * 3600) + (My.Settings.meditatemin * 60) + My.Settings.meditatesec) Then
                    Dim ameditatehour As Double = meditationTotalTime / 3600
                    Dim meditatehour As Double = Math.Floor(ameditatehour)
                    My.Settings.meditatehour = My.Settings.meditatehour + meditatehour
                    meditationTotalTime = meditationTotalTime - (meditatehour * 3600)
                    Dim ameditatemin As Double = meditationTotalTime / 60
                    Dim meditatemin As Double = Math.Floor(ameditatemin)
                    My.Settings.meditatemin = My.Settings.meditatemin + meditatemin
                    meditationTotalTime = meditationTotalTime - (meditatemin * 60)
                    My.Settings.meditatesec = My.Settings.meditatesec + meditationTotalTime
                End If
            End If
            If My.Settings.meditatesec >= 60 Then
                Dim amin As Double = My.Settings.meditatesec / 60
                Dim min As Double = Math.Floor(amin)
                My.Settings.meditatemin = My.Settings.meditatemin + min
                My.Settings.meditatesec = My.Settings.meditatesec - (min * 60)
            End If
            If My.Settings.meditatemin >= 60 Then
                Dim ahour As Double = My.Settings.restartmin / 60
                Dim hour As Double = Math.Floor(ahour)
                My.Settings.meditatehour = My.Settings.meditatehour + hour
                My.Settings.meditatemin = My.Settings.meditatemin - (hour * 60)
            End If
            If My.Settings.meditatehour >= 24 Then
                Dim aday As Double = My.Settings.meditatehour / 24
                Dim day As Double = Math.Floor(aday)
                My.Settings.meditatehour = My.Settings.meditatehour - (day * 24)
            End If
        End Sub

    Wednesday, September 19, 2012 7:20 PM

Answers

  • Your event  is a FormLoad event.

    I guess you want check values timer sensilbe add the timer event to your form load event.
    Actually your values are only checked when your form is loaded.


    Liebe Grüße Stefan | Cheers Stefan I'm using VB 2008 and VB 2010 Express Be a good forum member - mark posts that contain the answers to your questions or those that are helpful. c# in vb Translator: http://www.developerfusion.com/tools/convert/csharp-to-vb/

    Monday, September 24, 2012 8:31 AM

All replies

  • Hi Mac70,

    Thanks for posting question on MSDN forum.

    I need some time to reproducing the issue and check in detail. Once I find any useful info, I will let you know.

    If there is anything else, please feel free to let me know.

    Regards,


    Alan Yao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, September 20, 2012 9:02 AM
  • Hi Mac70,

    It seems the https://dl.dropbox.com/u/67758055/Wu...%20problem.zip is not valid. Could you please have a check?

    Thanks,


    Alan Yao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, September 24, 2012 5:51 AM
  • Your event  is a FormLoad event.

    I guess you want check values timer sensilbe add the timer event to your form load event.
    Actually your values are only checked when your form is loaded.


    Liebe Grüße Stefan | Cheers Stefan I'm using VB 2008 and VB 2010 Express Be a good forum member - mark posts that contain the answers to your questions or those that are helpful. c# in vb Translator: http://www.developerfusion.com/tools/convert/csharp-to-vb/

    Monday, September 24, 2012 8:31 AM