Re: Man in the middle

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Well I never knew of the Median function, probably because it ...
- is not in my Excel 2000 help.
- is not a choice with automatic completion in the VBA editor.

However I would still shy away from it because its syntax is poorly thought
out. It appears to only accept an explicit list of variables, not an array.
If the OP's boss is delighted with his skill in solving the problem, he's
got some woe when the boss wants the median of 1001 items.

BTW, for closure, I'll painfully complete the OP's question:
If dVar1 > dVar2 Then
temp = dVar2
dVar2 = dVar1
dVar1 = temp
End If
If dVar2 > dVar3 Then
temp = dVar3
dVar3 = dVar2
dVar2 = temp
End If
If dVar1 > dVar2 Then
temp = dVar2
dVar2 = dVar1
dVar1 = temp
End If

Note that this is nothing more than an ugly implementation of the bubble
sort algorithm I explained.

Luke

"Tom Ogilvy" <TomOgilvy@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:9F6BED9C-E26E-4ACB-B1BC-660F746FDF7D@xxxxxxxxxxxxxxxx
If the there are an odd number of variables, the Median function
eliminates
all that for you. If it isn't an odd number, what would be the definition
of
the middle value? <g>

--
Regards,
Tom Ogilvy


"Luke Alcatel" wrote:

I would advise you not to develop a specialized solution that only works
for
the case of 3 items since you'll need to re-solve the problem when your
boss
decides s/he wants to see the middle (wo)man of 5 items. The general
procedure is to sort your list and take the middle item from the list.
A
simple explanation of bubble sort is:
1. Place your data in an array if N items
2. Create an outer loop that loops from N-1 to 1
3. Create in inner loop that loops from 0 to the value of the outer loop
variable (J).
4. In the inner loop compare item(J) to item (J+1) and swap if they are
out
of order.
5. When the outer loop finishes the list is sorted. You can optimize it
by
keeping track of whether there were any swaps in an iteration of the
inner
loop and the first time there isn't one, your list is sorted.

There are quicker sorts but this is most suitable for a problem like
yours.
I may have made some (hopefully) minor mistakes by regurgitating this
from
memory but it's a good mental exercise to verify the logic.

Luke

"XP" <XP@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:938B3404-4FCE-4EC5-87DF-F2C34296B740@xxxxxxxxxxxxxxxx
I am using Office 2003 on Windows XP.

In code, I need to work out which variable contains the middle value,
in
this example, it would be 85. I would guess this needs to be done by
comparing <= and >= and sometimes there could be a two or three way
tie.
In a
tie, it doesn't matter which one is in the middle...but the code needs
to
identify which variable has been selected. So in the example, I would
need
to
know that dVar1 is in the
middle.

Dim dVar1 as Double
Dim dVar2 as Double
Dim dVar3 as Double
dVar1 = Abs(-85)
dVar2 = Abs(95)
dVar3 = Abs(25)

If dVar1 >= dVar2 then ... (what next? I can't crack it!)

Do I have to try every combination to work this out? I can't seem to
work
out the code to ensure that it always works. Your help is appreciated.






.



Relevant Pages

  • Re: Man in the middle
    ... If dVar1> dVar2 Then ... temp = dVar2 ... Create in inner loop that loops from 0 to the value of the outer loop ... Dim dVar1 as Double ...
    (microsoft.public.excel.programming)
  • Re: Performance of signed vs unsigned types
    ... If your computer can increment a 64-bit long in 1 nanosecond ... That takes about 6 seconds on my system (with no ouput in the loop). ... signed long temp; ... The function is the same for the unsigned longs, except with the types of the two counter variables changed to unsigned. ...
    (comp.lang.c)
  • Re: Performance of signed vs unsigned types
    ... If your computer can increment a 64-bit long in 1 nanosecond ... That takes about 6 seconds on my system (with no ouput in the loop). ... signed long temp; ... The function is the same for the unsigned longs, except with the types of the ...
    (comp.lang.c)
  • Re: do expression
    ... loop variable i by binding, ... To make your transformation fully general, ... (inits (mapcar #'second vars)) ... ;; evaluate init forms and save results in temp vars ...
    (comp.lang.scheme)
  • Re: simple and annoying
    ... Processes only update signals when they exit or when they encounter a wait ... Your process gets trigerred when datain changes and then it ... enters the loop. ... Since 'temp' is a signal it won't get updated until the ...
    (comp.lang.vhdl)