# 用兩種不同的方法來求實現數字字串的最大，最小和平均值

<%@ LANGUAGE = "VBScript"
ENABLESESSIONSTATE = False %>
<%
'1. Selecting the numbers from a string:
myString = "2, 4, 6, 8, 10, 12"
aValues = Split(myString, ",", -1, 1)</P><P>Function Min(someNumbers)
dblLowestSoFar = Null
If CDbl(someNumbers(I)) < dblLowestSoFar Or IsNull(dblLowestSoFar) Then
End If
End If
Next
Min = dblLowestSoFar
dblHighestSoFar = Null
If CDbl(someNumbers(I)) > dblHighestSoFar Or IsNull(dblHighestSoFar) Then
End If
End If
Next
Max = dblHighestSoFar
dblHighestSoFar = Null
If CDbl(someNumbers(I)) > dblHighestSoFar Or IsNull(dblHighestSoFar) Then
End If
End If
Next
Avg = dblHighestSoFar
End Function</P><P>'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
%>

## E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

## Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

## Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth \$300-1200 USD