Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 17th, 2003, 02:10 PM
nitrous nitrous is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 3 nitrous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old October 18th, 2003, 02:35 AM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via MSN to cleverpig
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...

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > Commenting Help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway