Results 1 to 9 of 9

Thread: VB Beginner - Need help using Time of Day

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2016
    Posts
    28

    VB Beginner - Need help using Time of Day

    Hey everybody, I am making a program to help manage Diabetes for my own personal Use.

    There is an Insulin Calculation section where the amount of Carbohydrates in a meal is divided by the Insulin Ratio that is stored. However this insulin ratio will change per Time of day.

    These values will be stored in an sql database using a different part of the program and then whatever one is needed per time of day will be called to be used in the program.

    The sql code isn't a problem, just the part where the time of day affects the choice of ratio.

  2. #2
    Registered User
    Join Date
    Nov 2016
    Posts
    51

    Re: VB Beginner - Need help using Time of Day

    What do you need with Time of Day, exactly? Do you need to use it on a calculation?
    Do you have a formula with needs a DateTime value to return an Integer?

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Dec 2016
    Posts
    28

    Re: VB Beginner - Need help using Time of Day

    The time of day will act almost as an IF statement, so if its between say 6am and 12mid day it will choose value 1 to use in the calculation. And then so on and so forth for different time periods of the day.

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Dec 2016
    Posts
    28

    Re: VB Beginner - Need help using Time of Day

    Quote Originally Posted by Tucalipe View Post
    What do you need with Time of Day, exactly? Do you need to use it on a calculation?
    Do you have a formula with needs a DateTime value to return an Integer?
    The time of day will act almost as an IF statement, so if its between say 6am and 12mid day it will choose value 1 to use in the calculation. And then so on and so forth for different time periods of the day.

  5. #5
    Registered User
    Join Date
    Nov 2016
    Posts
    51

    Re: VB Beginner - Need help using Time of Day

    Something along the lines of
    Code:
    If time > CDate(00:60:00) AND time < CDate(12:00:00) Then
        Something
    Elif time > CDate(12:00:00) AND time < CDate(18:00:00) Then
        Something
    Else Then
        Something
    End If
    Careful not to have too many Elif clauses. Isn't there a formula you can use?

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Dec 2016
    Posts
    28

    Re: VB Beginner - Need help using Time of Day

    Quote Originally Posted by Tucalipe View Post
    Something along the lines of
    vb Code:
    1. If time > 00:60:00 AND time < 12:00:00
    2. Then
    3. Something
    4. Elif
    5. time > 12:00:00 AND time 18:00:00
    6. Then
    7. Something
    8. Else
    9. Then
    10. Something
    11. End If

    Careful not to have too many Elif clauses. Isn't there a formula you can use?
    For the calculation?

  7. #7
    Registered User
    Join Date
    Nov 2016
    Posts
    51

    Re: VB Beginner - Need help using Time of Day

    Code:
    Dim time As DateTime = Now()
    Dim ratio As Integer = 1
    If time > CDate(00:60:00) AND time < CDate(12:00:00) Then
        ratio = 1
    Elif time > CDate(12:00:00) AND time < CDate(18:00:00) Then
        ratio = 2
    End If
    Then use ratio on your calculation. This will give the ratio according to the current time.

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Dec 2016
    Posts
    28

    Re: VB Beginner - Need help using Time of Day

    Quote Originally Posted by Tucalipe View Post
    Code:
    Dim time As DateTime = Now()
    Dim ratio As Integer = 1
    If time > CDate(00:60:00) AND time < CDate(12:00:00) Then
        ratio = 1
    Elif time > CDate(12:00:00) AND time < CDate(18:00:00) Then
        ratio = 2
    End If
    Then use ratio on your calculation. This will give the ratio according to the current time.
    Awesome, Thank you so much, I will try this now and see if it works.

  9. #9
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: VB Beginner - Need help using Time of Day

    Now.TimeOfDay returns a TimeSpan. Try this:

    Code:
    Dim value As Integer = -1
    Dim t As TimeSpan = Now.TimeOfDay
    If t >= New TimeSpan(6, 0, 0) And t < New TimeSpan(12, 0, 0) Then
        value = 1
    ElseIf t >= New TimeSpan(12, 0, 0) And t < New TimeSpan(18, 0, 0) Then
        value = 2
    ElseIf t >= New TimeSpan(18, 0, 0) And t < New TimeSpan(24, 0, 0) Then
        value = 3
    ElseIf t >= New TimeSpan(0, 0, 0) And t < New TimeSpan(6, 0, 0) Then
        value = 4
    End If

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