Answered by:
Divide Number by Real Time
Question

Hi,
I currently have a sum of numbers that are returned from my SQL for our sales orders, I also have a column that returns the seconds from the SQL. I used this below to convert the seconds to Time.
Public Function SecondsToHours(ByVal secs As Integer) As String Dim ts As New TimeSpan(0, 0, secs) Dim hoursStr As String = String.Format( _ "{0:00}:{1:00}:{2:00}", _ ts.TotalHours, ts.Minutes, ts.Seconds) Return hoursStr End Function
However I think it is string time and not real time. When I try to divide the number of sales orders by this time that is returned above I get an #Error in my textbox.
I have tried many variations of this expression below but cant get past the Error.
=cint(reportitems!Textbox75.value)/reportitems!Textbox84.Value
So is there a way to convert the time returned from the function above into real time so I can divide the Sales Orders by the Time to get Orders / Hour?
Thanks for any help or suggestions.
Mike
Tuesday, July 31, 2012 8:14 PM
Answers

Hi Realniceguy5000,
I feel that you can do this without resorting to any custom code at all.
Let's assume you have two fields in your dataset:
NumberOfOrders (Fields!NumberOfOrders.Value)  this represents the number of orders in your database
NumberOfSeconds (Fields!NumberOfSeconds.Value)  this represents the number of seconds
So, in your textbox where you need to calculate the "Orders / Hour", you can place the expression as shown below:
=Fields!NumberOfOrders.Value / (((Fields!NumberOfSeconds.Value)/60)/60)
What we do here is:
1. In the denominator, we convert the seconds into minutes, and then the minutes into hours.
2. Then divide the orders by the value obtained from step 1.
As an example, you can see the image below that shows a sample o/p:
If you multiply the "Seconds to Hours" Field and the "Orders / Hour" Field, you will get the Number of Orders.
Let me know if you need more info.
HTH.
Cheers,
IceQB
Please mark correct answers :)
 Proposed as answer by Edward Zhu Thursday, August 2, 2012 8:51 AM
 Marked as answer by Realniceguy5000 Thursday, August 2, 2012 11:41 AM
Wednesday, August 1, 2012 6:53 AM
All replies

Hi Realniceguy5000,
I feel that you can do this without resorting to any custom code at all.
Let's assume you have two fields in your dataset:
NumberOfOrders (Fields!NumberOfOrders.Value)  this represents the number of orders in your database
NumberOfSeconds (Fields!NumberOfSeconds.Value)  this represents the number of seconds
So, in your textbox where you need to calculate the "Orders / Hour", you can place the expression as shown below:
=Fields!NumberOfOrders.Value / (((Fields!NumberOfSeconds.Value)/60)/60)
What we do here is:
1. In the denominator, we convert the seconds into minutes, and then the minutes into hours.
2. Then divide the orders by the value obtained from step 1.
As an example, you can see the image below that shows a sample o/p:
If you multiply the "Seconds to Hours" Field and the "Orders / Hour" Field, you will get the Number of Orders.
Let me know if you need more info.
HTH.
Cheers,
IceQB
Please mark correct answers :)
 Proposed as answer by Edward Zhu Thursday, August 2, 2012 8:51 AM
 Marked as answer by Realniceguy5000 Thursday, August 2, 2012 11:41 AM
Wednesday, August 1, 2012 6:53 AM 
Thank You for taking the time to help, Your soultion was just what I needed to move my project to the final stages. Works Great!!!
Thanks Again, Mike
Thursday, August 2, 2012 11:43 AM