|
-
Jan 30th, 2007, 01:43 AM
#1
Thread Starter
Member
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
-
Jan 30th, 2007, 02:13 AM
#2
Re: Maximum Value
1. Store all the values in an array.
2.
VB Code:
Dim arr(10) As Integer
' find the largest
Dim n As Long, j As Single, k As Long
k = LBound(arr)
For n = LBound(arr) To UBound(arr)
If arr(n) > j Then j = arr(n): k = n
Next n
MsgBox arr(k)
Hope this helps!
-
Jan 30th, 2007, 08:04 AM
#3
Re: Maximum Value
If variables are already declared, to transfer them to an array
VB Code:
Dim aaa As Long
Dim bbb As Byte
Dim ccc As String
Dim MyArr As Variant
aaa = 5
bbb = 2
ccc = "weee"
MyArr = Array(aaa, bbb, ccc)
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|