Results 1 to 3 of 3

Thread: Maximum Value

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2005
    Posts
    52

    Maximum Value

    Hi Everybody,

    I have a simple question and request any one of you to provide me with a simple logic.

    I have 10 variables with 10 different values in it.
    I would like to find the maximum value from those variables. I dont want to use If Then Else statement. So can anyone help me out in this logic.

    Thanks in Advance.

    Rgrds

  2. #2
    Fanatic Member amrita's Avatar
    Join Date
    Jan 2007
    Location
    Orissa,India
    Posts
    888

    Re: Maximum Value

    1. Store all the values in an array.
    2.
    VB Code:
    1. Dim arr(10) As Integer
    2. ' find the largest
    3. Dim n As Long, j As Single, k As Long
    4. k = LBound(arr)
    5. For n = LBound(arr) To UBound(arr)
    6. If arr(n) > j Then j = arr(n): k = n
    7. Next n
    8.  
    9. MsgBox arr(k)

    Hope this helps!

  3. #3
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Maximum Value

    If variables are already declared, to transfer them to an array

    VB Code:
    1. Dim aaa As Long
    2. Dim bbb As Byte
    3. Dim ccc As String
    4. Dim MyArr As Variant
    5.  
    6.    aaa = 5
    7.    bbb = 2
    8.    ccc = "weee"
    9.  
    10.    MyArr = Array(aaa, bbb, ccc)
    11.    MsgBox MyArr(2)

Posting Permissions

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



Click Here to Expand Forum to Full Width