# 用两种不同的方法来求实现数字字符串的最大，最小和平均值（转）

<%@ LANGUAGE = "VBScript"
ENABLESESSIONSTATE = False %>
<%
'1. Selecting the numbers from a string:
myString = "2, 4, 6, 8, 10, 12"
aValues = Split(myString, ",", -1, 1)

dblLowestSoFar = Null
If CDbl(someNumbers(I)) < dblLowestSoFar Or IsNull(dblLowestSoFar) Then
End If
End If
Next
Min = dblLowestSoFar
End Function

dblHighestSoFar = Null
If CDbl(someNumbers(I)) > dblHighestSoFar Or IsNull(dblHighestSoFar) Then
End If
End If
Next
Max = dblHighestSoFar
End Function

dblHighestSoFar = Null
If CDbl(someNumbers(I)) > dblHighestSoFar Or IsNull(dblHighestSoFar) Then
End If
End If
Next
Avg = dblHighestSoFar
End Function

'2. Or, selecting the numbers from a database:
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")
%>

1. Selecting the numbers from a string:

The lowest number is: <%=Min(aValues)%>

The highest number is: <%=Max(aValues)%>

The average number is: <%=Avg(aValues)%>

2. Selecting the numbers from a database:

The lowest priced ad is: <%=FormatCurrency(Int(rsLo("loPRICE")))%>

The highest priced ad is: <%=FormatCurrency(Int(rsHi("hiPRICE")))%>

The average selling price of these ads is: <%=FormatCurrency(Int(rsAvg("avgPRICE")))%>

<%
cnDZ.Close
Set cnDZ = Nothing
rsLo.Close
Set rsLo = Nothing
rsHi.Close
Set rsHi = Nothing
rsAvg.Close
Set rsAvg = Nothing
%>

• 博文量
2948
• 访问量
2171175