lowest value in an array

# Thread: lowest value in an array

1. Senior Member
Join Date
Dec 1969
Posts
425

## lowest value in an array

Hi there if we have something like<BR><BR>price = Array(10.99, 11.99, 12.99)<BR><BR>How do i find out what the lowest value is in the array?

2. God
Senior Member
Join Date
Dec 1969
Posts
18,177

## Offhand, all I can think..

.. is to loop through the array and check each value against the rest of the array.<BR><BR>Dim lowest<BR>lowest = 10000000<BR>For iCnt = 0 To Ubound(price)<BR> If price(iCnt) &#060; lowest Then<BR> lowest = price(iCnt)<BR> End If<BR>Next<BR>Response.Write "lowest = " & lowest & "&#060;br /&#062;"

3. Senior Member
Join Date
Dec 1969
Posts
96,118

## There's a minor bug in that...

Although it&#039;s unlikely, it is *possible* that ALL the values in the array might be greater than the initial value of lowest that you chose, via <BR> lowest = 10000000<BR><BR>So there&#039;s an easy fix:<BR><BR>Dim lowest<BR>lowest = price(0) &#039; assume first value in array is lowest<BR>For iCnt = 1 To Ubound(price)<BR> If price(iCnt) &#060; lowest Then lowest = price(iCnt)<BR>Next<BR>Response.Write "lowest = " & lowest & "&#060;br /&#062;"<BR><BR>Now it works no matter what the values are.<BR><BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•