·您的位置: 首页 » 资源教程 » 编程开发 » ASP » 用两种不同的方法来求实现数字字符串的最大,最小和平均值

用两种不同的方法来求实现数字字符串的最大,最小和平均值

类别: ASP教程  评论数:0 总得分:0
用两种不同的方法来求实现数字字符串的最大,最小和平均值
<%@ LANGUAGE = "VBScript"
ENABLESESSIONSTATE = False %>
<%
\'1. Selecting the numbers from a string:
myString = "2, 4, 6, 8, 10, 12"
aValues = Split(myString, ",", -1, 1)

Function Min(someNumbers)
dblLowestSoFar = Null
For I = LBound(someNumbers) to UBound(someNumbers)
If IsNumeric(someNumbers(I)) Then
If CDbl(someNumbers(I)) < dblLowestSoFar Or IsNull(dblLowestSoFar) Then
dblLowestSoFar = CDbl(someNumbers(I))
End If
End If
Next
Min = dblLowestSoFar
End Function

Function Max(someNumbers)
dblHighestSoFar = Null
For I = LBound(someNumbers) to UBound(someNumbers)
If IsNumeric(someNumbers(I)) Then
If CDbl(someNumbers(I)) > dblHighestSoFar Or IsNull(dblHighestSoFar) Then
dblHighestSoFar = CDbl(someNumbers(I))
End If
End If
Next
Max = dblHighestSoFar
End Function

Function Avg(someNumbers)
dblHighestSoFar = Null
For I = LBound(someNumbers) to UBound(someNumbers)
If IsNumeric(someNumbers(I)) Then
If CDbl(someNumbers(I)) > dblHighestSoFar Or IsNull(dblHighestSoFar) Then
dblHighestSoFar = CDbl(someNumbers(I)) + CDbl(someNumbers(I)) /
End If
End If
Next
Avg = dblHighestSoFar
End Function

\'2. Or, selecting the numbers from a database:
Set cnDZ = Server.CreateObject("ADODB.Connection")
cnDZ.Open "DSN=myDatabase"
Set rsLo = cnDZ.Execute("SELECT Min(PRICE) AS loPRICE FROM TBLADS")
Set rsHi = cnDZ.Execute("SELECT Max(PRICE) AS hiPRICE FROM TBLADS")
Set rsAvg = cnDZ.Execute("SELECT Avg(PRICE) AS avgPRICE FROM TBLADS")
%>
<html>
<body>
1. Selecting the numbers from a string:<br>
The lowest number is: <%=Min(aValues)%><br>
The highest number is: <%=Max(aValues)%><br>
The average number is: <%=Avg(aValues)%><br>
<br>
2. Selecting the numbers from a database:<br>
The lowest priced ad is: <%=FormatCurrency(Int(rsLo("loPRICE")))%><br>
The highest priced ad is: <%=FormatCurrency(Int(rsHi("hiPRICE")))%><br>
The average selling price of these ads is: <%=FormatCurrency(Int(rsAvg("avgPRICE")))%>
</body>
</html>
<%
cnDZ.Close
Set cnDZ = Nothing
rsLo.Close
Set rsLo = Nothing
rsHi.Close
Set rsHi = Nothing
rsAvg.Close
Set rsAvg = Nothing
%>
-= 资 源 教 程 =-
文 章 搜 索
关键词:
类型:
范围:
纯粹空间 softpure.com
Copyright © 2006-2008 暖阳制作 版权所有
QQ: 15242663 (拒绝闲聊)  Email: faisun@sina.com
 纯粹空间 - 韩国酷站|酷站欣赏|教程大全|资源下载|免费博客|美女壁纸|设计素材|技术论坛   Valid XHTML 1.0 Transitional
百度搜索 谷歌搜索 Alexa搜索 | 粤ICP备19116064号-1