|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Commenting Help
A buddy of mine wrote this code and i am needing some help to understand it...you guys able to help me out?? or comment some of it? thanks, oh and if you feel something should be changed let me know
Private Function GetFeedDisappearance(ByVal lngdropID As Long, sngPeriodLength As Single) As Single Dim strSQL As String Dim strDateSQL As String strSQL = "SELECT DropDateTime FROM DropHistory" _ & " WHERE DropFull = True AND DropID = " & CStr(lngdropID) _ & " ORDER BY DropDateTime DESC" With rsTemp .Open strSQL, cnMain, adOpenForwardOnly, adLockReadOnly, adCmdText If .BOF And .EOF Then mdtmLastDate = 0 GetFeedDisappearance = 0 mdtmFirstDate = 0 msngTotalFeedUsage = 0 msngUsagePeriod = 0 .Close Exit Function Else mdtmLastDate = !DropDateTime mdtmFirstDate = !DropDateTime Do .MoveNext If .EOF Then GetFeedDisappearance = 0 mdtmFirstDate = 0 msngTotalFeedUsage = 0 msngUsagePeriod = 0 .Close Exit Function Else mdtmFirstDate = !DropDateTime End If Loop Until (mdtmLastDate - mdtmFirstDate) > sngPeriodLength End If .Close End With strDateSQL = " WHERE DropDateTime > #" & CStr(mdtmFirstDate) _ & "# AND DropDateTime <= #" & CStr(mdtmLastDate) & "#" strSQL = "SELECT SUM(TotalByWeight) FROM DropHistory" & strDateSQL _ & " AND DropID = " & CStr(lngdropID) With rsTemp .Open strSQL, cnMain, adOpenForwardOnly, adLockReadOnly, adCmdText msngTotalFeedUsage = rsTemp(0).Value .Close End With msngUsagePeriod = mdtmLastDate - mdtmFirstDate GetFeedDisappearance = msngTotalFeedUsage / msngUsagePeriod |
|
#2
|
|||
|
|||
|
I try my best to help u!This is my expaining for this code:
At the first: run sql statement to find some recordsets that have DropFull = True AND DropID = " & CStr(lngdropID).. If can't find any recordset in the db,it will have two error like EOF and BOF.The function will return some result variables as:mdtmLastDate = 0 GetFeedDisappearance = 0 mdtmFirstDate = 0 msngTotalFeedUsage = 0 msngUsagePeriod = 0 And Close the sql connecttion,Exit function; Comment: BOF returns a value that indicates whether the current record position is before the first record in a Recordset object. EOF returns a value that indicates whether the current record position is after the last record in a Recordset object. 2th:if find EOF,then have no recordset according with having "DropFull = True AND DropID = " & CStr(lngdropID) ".The function will return some result,close the connection. 3rd:find some recordsets according with the condition,the function will get the SUM of the(TotalByWeight) between the mdtmLastDate and mdtmFirstDate,calculate some result to return... |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > Commenting Help |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|