Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

miniumum

Status
Not open for further replies.

sharonc

Programmer
Jan 16, 2001
189
US
I have five numbers: Text183, text202, text204, text206, text208

I need to select the miniumum number from these five numbers, keeping in mind that if the number is 0 I don't want to select it.

Does anyone know how I can do this without writting 25 pages of code?
 
I assume that you have these 5 text boxes on a form and you will click a button and be told the minimum number (excluding 0's)?

Nick
 
There is one text box and the result from the minimum of these 5 numbers will go on the form in the text box.

The code is written in VBA.
 
Since you do not specify a type or range for the values entered intot he text boxes, you may want or need to adjust the initial assignment for MyArray(0).

You also did not note the actual names of the six text boxes, so these will also need to conformed to the names in use on your form.

The code below is certainly less than ' ... 25 pages ... ', but then I have a hard time imagiining 25 pages of code for such a process.

Since so very little of the details were provided, this function is quite generic. It needs (in this form) to part of the 'code behind forms' or -in the current terminology- in the Forms Module of the form where you have the six textboxes. Use the return value from this module to set the value of the min textbox. Call this from the after update of each of the five independent value text boxes and any other place which MAY set or change the text boxes.


Code:
Public Function bastxt5Min() As Varaint

    Dim MyArray(4) As Variant
    Dim Idx As Integer

    MyArray(0) = 1 ^ 99
    MyArray(1) = Nz(txtBox1)
    MyArray(2) = Nz(txtBox2)
    MyArray(3) = Nx(txtBox3)
    MyArray(4) = Nz(txtBox4)
    MyArray(5) = Nz(txtBox5)

    For Idx = 1 To UBound(MyArray)
        If (MyArray(Idx) <> 0 And MyArray(Idx) < MyArray(0)) Then
            MyArray(0) = MyArray(Idx)
        End If
    Next Idx

    bastxt5Min = MyArray(0)

End Function
MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
thank you for the suggestion. I will give it a try.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top