Two different ways to achieve the maximum, minimum and average number of numeric strings

Source: Internet
Author: User
A string uses two different methods to achieve the maximum, minimum, and average number of numeric strings.
<%@ 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
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</p><p>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</p><p>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</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")
%>
<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 this ads is: <%=formatcurrency (Int (Rsavg ("Avgprice"))%>
</body>
<%
Cndz.close
Set Cndz = Nothing
Rslo.close
Set Rslo = Nothing
Rshi.close
Set Rshi = Nothing
Rsavg.close
Set Rsavg = Nothing
%>


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.