Click to See Complete Forum and Search --> : Calculation for a dataList


nelslynn
09-30-2003, 01:01 AM
I am using an asp datalist to display the results of a query. This is accomplished in the Page_load Sub. There is one calulation that needs to be done before I display the results. I need to divide a hours and minutes field by a number (miles) to display pace Per Mile. For Example: (hh:mm)/2.25. How do I accomplish this?

The calculation subroutine is too complicated for the query... here's the calcultion as a VB function:

Public Function fPace(mi As Double, t As Date) As String
Dim tSec As Long
Dim hrs As Integer
Dim mins As Integer
Dim secs As Integer
Dim secMi As Integer
Dim temp As Date
Dim ret As String

tSec = (Hour(t) * 3600) + (Minute(t) * 60) + Second(t)
secMi = Int(tSec / mi)
hrs = Int(secMi / 3600)
mins = Int((secMi - (hrs * 3600)) / 60)
secs = secMi - ((hrs * 3600) + (mins * 60))

Select Case hrs
Case Is = 0
fPace = mins & ":" & Format(secs, "00")
'fPace = CInt(mins) & ":" & Format(CInt(secs), "00")
Case Else
fPace = hrs & ":" & Format(mins, "00") & ":" & Format(secs, "00")
End Select

End Function

I get the hh:mm (split1) from the query and display it like:
<TD class="text" width="30"><%# DataBinder.Eval(Container.DataItem, "split1") %></TD>

Thanks for any help

Ribeyed
09-30-2003, 02:30 PM
Hi,
not entirely sure what it is you want but hope this helps and answer your question:


<%
'exstracting hours and mins from the VB now function
thehour = datepart(h, now())
themins = datepart(m, now())

'use an sql query for extracting the hour and mins from a date/time field

sql = "SELECT DATEPART(h,[datetime]) AS thehours, DATEPART(n,[datetime]) AS themins, "
sql = sql & "tblTimes.RecordID FROM tblTimes "


totaltimeinmins = (thehour * 60) + themins

'calculate the time in mins taken to 1 mile
pacepermileinmins = totaltimeinmins / milestraveled
'calculate the time in hours taken to travel 1 mile
pacepermileinhours = pacepermileinmins / 60

'
%>

nelslynn
10-01-2003, 02:19 AM
Okay, how to I use this code in my .asp page?

I'm displaying the hours:minutes in my table like this
("split1" is a field retrieved from a query in the page_load):

<td>#Container.DataItem("split1")%></td>

I would like to now take the "split1" value and calculate the pace (based on the code provided). I will also be providing the 'miles' value. I would like to display this figure in the <td> next to the "split1".

Thanks

Ribeyed
10-01-2003, 02:45 AM
hi,
the answer i gave you is in classic ASP, but it looks like your useing ASP.NET therefore the syntax may change slightly.

nelslynn
10-01-2003, 05:05 AM
Yes, I'm using ASP.NET.... Can anyone else help me here?