Max/Min Functions



I put together the following little snippet of code to determine Max/Min
values with two arguments. I think it was JGM that posted the min function
a while back and I just reversed the equality signs to make the max function
work:

Sub Test()
Dim i As Long
i = min(1, 1000)
MsgBox i
i = max(5, 500)
MsgBox i
End Sub
Private Function min(a As Long, b As Long)
min = -((a < b) * a + (a >= b) * b)
End Function
Private Function max(a As Long, b As Long)
max = -((a > b) * a + (a <= b) * b)
End Function

Does anyone know if someone has figure out how to determine max or min
values in an array using Word VBA? Thanks.

--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.


.



Relevant Pages

  • Re: Max/Min Functions
    ... with arrays and passing things. ... >> Sub Test() ... >> MsgBox i ... >> Private Function min ...
    (microsoft.public.word.vba.general)
  • Re: Max/Min Functions
    ... >> Sub Test() ... >> MsgBox i ... >> Private Function min ... >> Greg Maxey/Word MVP ...
    (microsoft.public.word.vba.general)
  • Re: Max/Min Functions
    ... As a separate issue (although relevant if you're testing large arrays) your ... > MsgBox i ... > Private Function min ... > values in an array using Word VBA? ...
    (microsoft.public.word.vba.general)
  • Re: Max/Min Functions
    ... If you need to access the maximum and minimum values in an array often, ... > MsgBox i ... > Private Function min ... > values in an array using Word VBA? ...
    (microsoft.public.word.vba.general)
  • Re: Can one pass a Range object to a function?
    ... > I have a subroutine that sets a Range in a wORD97 document. ... Sub Test() ... Dim myRange As Range ... MsgBox "Text NOT found" ...
    (microsoft.public.word.vba.beginners)

Loading