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

    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
    Location
    Préverenges, Switzerland
    Posts
    3,740
    you can do it your way
    e.g.

    highest = price1
    if price2 > highest then highest = price2
    if price3 > highest then highest = price3
    ...etc
    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
    endif
    next


    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

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

  3. #3
    Join Date
    Apr 2004
    Posts
    3

    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
  •