Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2004

    Unhappy Unanswered: How to get highest value in VBA ?

    Hello ... i'm new on this forum ...
    First , excuse for my english

    So my question :

    How to get the highest value ?

    This is an exemple:

    Begin Sub
    Dim price1 as double
    Dim price2 as double
    Dim price3 as double
    Dim highest as double
    Dim highestname as string

    price1 = 1,15
    price2 = 1,04
    price3 = 3,05

    'On this moment we got 3 price in variables
    'How to get automaticly "3,05" for highest and
    ' "price3" for highestname ?

    End Sub

    Thanks a lot to everybody

  2. #2
    Join Date
    Dec 2002
    Préverenges, Switzerland
    you can do it your way

    highest = price1
    if price2 > highest then highest = price2
    if price3 > highest then highest = price3
    but this is a pain if you have to go to price999

    consider using an array:
    dim where as integer
    dim here as integer
    dim price(1 to 999) 'or whatever is your max (or use dynamic array)
    where = 1
    highest = price(1)
    for here = 2 to 999
    if price(here) > highest then
    highest = price(here) 'the highest price
    where = here 'which price is the highest

    but since we are talking about databases, this data is possibly coming from a table so you can get there with a query:
    SELECT TOP 1 price FROM yourTable ORDER BY price DESC

    ...or with a domain agregate function:
    highest = DMAX("[price]", "[yourTable]")

    choices choices choices

    Last edited by izyrider; 04-21-04 at 05:32.
    currently using SS 2008R2

  3. #3
    Join Date
    Apr 2004

    Thumbs up

    Thanx !!!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts