实现数字字符串的最大值、最小值和平均值
作者 佚名技术
来源 ASP编程
浏览
发布时间 2012-03-12
<%@ 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:< |
|
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |
你可能对下面的文章感兴趣
上一篇:
ASP教程:过滤HTML代码并截取
下一篇:
ASP简单入门教程(2):ASP环境配置
关于
实现数字字符串的最大值、最小值和平均值
的所有评论