Re: Max/Min Functions
- From: "Greg Maxey" <gmaxey@xxxxxxxxxxxxxxxxxxx>
- Date: Sat, 3 Dec 2005 09:29:41 -0500
Jezebel,
Thanks. Yes I see the simplicity of the multi-line approach. As you might
have read my reply to Jonathan you are aware that I am very inexperienced,
practically clueless, with arrays and passing things. I am sure that your
code snippet would work, I just don't have the skills to plug it in ;-).
--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.
"Jezebel" <warcrimes@xxxxxxxxxxxxxx> wrote in message
news:%23U1R4S99FHA.3312@xxxxxxxxxxxxxxxxxxxxxxx
> You can use code along these lines --
>
> pMax = srcArray(lbound(srcArray))
>
> For pIndex = lbound(srcArray) To ubound(srcArray) - 1
> pValue = Max(srcArray(pIndex), srcArray(pIndex + 1))
> If pValue > pMax Then
> pMax = pValue
> End If
> Next
>
>
> As a separate issue (although relevant if you're testing large arrays)
> your min/max functions, notwithstanding their one-line elegance, are
> actually rather inefficient because they involve two comparisons and three
> arithmetic operations. Quicker (use GetTickCount to measure it) is the
> simple --
>
> If a > b Then
> Max = a
> Else
> Max = b
> End If
>
>
>
>
>
> "Greg Maxey" <gmaxey@xxxxxxxxxxxxxxxxxxx> wrote in message
> news:%237m8Y579FHA.2320@xxxxxxxxxxxxxxxxxxxxxxx
>>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.
>>
>
>
.
- References:
- Max/Min Functions
- From: Greg Maxey
- Re: Max/Min Functions
- From: Jezebel
- Max/Min Functions
- Prev by Date: Re: Max/Min Functions
- Next by Date: Re: Max/Min Functions
- Previous by thread: Re: Max/Min Functions
- Next by thread: Re: Max/Min Functions
- Index(es):
Relevant Pages
|