CodeItBetter Programming Another VB Programming Blog

How to return the smallest parameter value.

Posted on January 4, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
'Math - How to return the smallest parameter value.
Option Explicit
 
Private Function Min(ParamArray values() As Variant) As Variant
    Dim i As Integer
    Dim min_value As Variant
 
    min_value = values(LBound(values))
    For i = LBound(values) + 1 To UBound(values)
        If min_value > values(i) Then min_value = values(i)
    Next i
 
    Min = min_value
End Function
 
'Call this function as:
'    txtMin.Text = Format$(Min(CInt(txtValue1.Text), CInt(txtValue2.Text), CInt(txtValue3.Text), _
'    CInt(txtValue4.Text), CInt(txtValue5.Text), CInt(txtValue6.Text), CInt(txtValue7.Text), _
'    CInt(txtValue8.Text)))

Related posts:

  1. How to return the biggest parameter value.
  2. How to Use ADO’s GetRows method to quickly load data into an array
  3. How to generate a random number, in between two given values.
  4. How to Convert text into the Currency data type
  5. How to sum all the elements in an array
  6. How to Return the number of records in the table.
  7. How to Read Line By Line & Retrieve Each Word From Text File
  8. How to Return a specific line number from a file (note: first line = line number 0)
  9. How to Return Short path for given file (with long path)
  10. How to return Quotient and Remainder for given two numbers

Filed under: Math Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


No trackbacks yet.