Advertisement

06.16.2008 at 08:41AM PDT, ID: 23488542
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.6

Calculating an interval of time

Asked by sgaggerj in Microsoft Visual Basic.Net

Tags:

Hi all,

i need to figure out how to calculate an interval of time - in ms.
I am working on a backup project that the user will run, select the date and time of the next run and then start the program.
This program will run on that day and time, then reset and run again the same day and time the next week.


For example, the user starts the program on Monday, at 11:24 am.
They select Friday, at 20:30 (8:30 pm) and start the program.  The code below calculates the number of ms for the interval of the System.Timers.Timer
Friday at 20:30 comes, the program runs and resets itself to run the next friday at 20:30 (recalculating the new interval)

what i'm needing to calculate is the interval from when the user clicks 'start' until the program actually runs.

What I have so far is
2 combo-boxes
(DayBox)  with Sunday-Saturday, so that the indecies of the combobox correspond with Date.DayOfWeek values, ie Sunday=0, Monday=1, etc)

(TimeBox) with times (in 24h format, in 30 minute increments - ie 00:00, 00:30, 01:00 ...... 23:00,23:30)

The following code seems to work, but after writing it, it seems very cumbersome.
Does anyone have a simpler, or more elegant way to do this?
Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
Private Enum MSeconds
        Days = 86400000
        Hours = 3600000
        Minutes = 60000
        Seconds = 1000
End Enum
 
Private Function GetNextInterval() As Long
        Dim day As Integer = Now.DayOfWeek
        Dim day2 As Integer = DayBox.SelectedIndex
        Dim d As Integer = 0
        Dim h As Integer = CInt(Split(TimeBox.Text, ":")(0))
        Dim m As Integer = CInt(Split(TimeBox.Text, ":")(1))
        Dim s As Integer = 0
        ' number of days til next backup
        If day > day2 Then
            ' if today is past backup day
            d = 7 - (day - day2)
        ElseIf day2 > day Then
            d = day2 - day
        Else
            'day=day2
            Dim time As New Date(Now.Year, Now.Month, Now.Day, h, m, s)
            Dim ts As TimeSpan = time - Now
            If ts.TotalMilliseconds > 0 Then
                ' its passed already
                d = 6
            Else
                d = 0
            End If
        End If
 
        ' number of hours
        If h = 0 Then
            ' use 24
            If Now.Hour = 0 Then
                h = 0
            Else
                h = 24 - Now.Hour
            End If
        Else
            If h > Now.Hour Then
                h = h - Now.Hour
            ElseIf h < Now.Hour Then
                h = 24 - (Now.Hour - h)
            Else
                h = 0
            End If
        End If
        ' number of minutes
        If m = 0 Then
            ' use 60
            If m = Now.Minute Then
                m = 0
            Else
                m = 60 - m
            End If
        ElseIf m = 30 Then
            If m > Now.Minute Then
                m = 30 - Now.Minute
            Else
                m = 60 - (Now.Minute - m)
            End If
        End If
        ' number of secods - leave at 0
        s = 0
        Return d * MSeconds.Days + h * MSeconds.Hours + m * MSeconds.Minutes + s * MSeconds.Seconds
    End Function
[+][-]06.16.2008 at 08:55AM PDT, ID: 21794819

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.16.2008 at 09:03AM PDT, ID: 21794908

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]06.16.2008 at 09:11AM PDT, ID: 21794978

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.16.2008 at 10:48AM PDT, ID: 21795831

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.16.2008 at 11:10AM PDT, ID: 21796008

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Microsoft Visual Basic.Net
Tags: Vb.Net 2005
Sign Up Now!
Solution Provided By: Idle_Mind
Participating Experts: 3
Solution Grade: A
 
 
[+][-]06.16.2008 at 11:11AM PDT, ID: 21796013

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.16.2008 at 12:44PM PDT, ID: 21796789

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.16.2008 at 12:55PM PDT, ID: 21796892

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.16.2008 at 01:05PM PDT, ID: 21796996

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]06.16.2008 at 01:13PM PDT, ID: 21797080

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080924-EE-VQP-39 / EE_QW_2_20070628