-
Dec 10th, 2016, 11:16 AM
#1
Thread Starter
Junior Member
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.
-
Dec 10th, 2016, 11:24 AM
#2
Registered User
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?
-
Dec 10th, 2016, 11:25 AM
#3
Thread Starter
Junior Member
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.
-
Dec 10th, 2016, 11:29 AM
#4
Thread Starter
Junior Member
Re: VB Beginner - Need help using Time of Day
Originally Posted by Tucalipe
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.
-
Dec 10th, 2016, 11:30 AM
#5
Registered User
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?
-
Dec 10th, 2016, 11:32 AM
#6
Thread Starter
Junior Member
Re: VB Beginner - Need help using Time of Day
Originally Posted by Tucalipe
Something along the lines of
vb Code:
If time > 00:60:00 AND time < 12:00:00 Then Something Elif time > 12:00:00 AND time 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?
For the calculation?
-
Dec 10th, 2016, 11:36 AM
#7
Registered User
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.
-
Dec 10th, 2016, 11:38 AM
#8
Thread Starter
Junior Member
Re: VB Beginner - Need help using Time of Day
Originally Posted by Tucalipe
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.
-
Dec 10th, 2016, 11:44 AM
#9
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|