/ Published in: ASP

URL: http://reusablecode.blogspot.com/2009/05/fuel-consumption.html
Expand |
Embed | Plain Text
<% ' Copyright (c) 2009, reusablecode.blogspot.com; some rights reserved. ' ' This work is licensed under the Creative Commons Attribution License. To view ' a copy of this license, visit http://creativecommons.org/licenses/by/3.0/ or ' send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California ' 94305, USA. ' NOTE: The "magic numbers" in these functions are from the 2007 Fuel Consumption Guide ' published by Natural Resources Canada and use a conversion of 4.546 L = 1 imperial gallon. ' U.S. fuel economy ratings use U.S. gallons which are 20% smaller than imperial gallons. ' Calculate fuel consumption rating in litres per 100 kilometres. function lph(kilometres, litres) lph = (litres * 100) / kilometres end function ' Calculate fuel consumption rating in miles per gallon. function mpg(miles, gallons) mpg = miles / gallons end function ' Convert miles per (imperial) gallon to litres per 100 kilometres. function lph2mpg(mpg) lph2mpg = 282.48 / mpg end function ' Convert litres per 100 kilometres to miles per (imperial) gallon. function mpg2lph(lph) mpg2lph = 282.48 / lph end function ' Calculate fuel consumption in litres. ' distanceTravelled = the distance travelled in kilometres; e.g. 20000 ' percentCity = the percentage of the distance travelled occuring in the city; e.g. 0.55 ' percentHighway = the percentage of the distance travelled occuring on the highway; e.g. 0.45 ' ratingCity = city fuel consumption rating in litres per 100 kilometres; e.g. 7.9 ' ratingHighway = highway fuel consumption rating in litres per 100 kilometres; e.g. 5.9 function fuelConsumption(distanceTravelled, percentCity, percentHighway, ratingCity, ratingHighway) dim cityConsumption dim highwayConsumption cityConsumption = (distanceTravelled * percentCity * ratingCity) / 100 highwayConsumption = (distanceTravelled * percentHighway * ratingHighway) / 100 fuelConsumption = cityConsumption + highwayConsumption end function ' Calculate carbon dioxide emissions in kilograms. function CO2emissions(fuelConsumption, fuelType) select case fuelType case "diesel" CO2emissions = fuelConsumption * 2.7 case else ' gasoline CO2emissions = fuelConsumption * 2.4 end select end function %>
You need to login to post a comment.