473,383 Members | 1,805 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

return largest value?

MLH
Is there any built-in FN for returning largest value
in a group of say 2 - 10 values? Lets say I want
a FN something like MaxVal(5, 7, 9, 3, 12) or
perhaps MaxVal(79,34). I would wanna see
return value of 12 and 79 respectively.

What's simplest way to do that in A97?
Jul 17 '08 #1
8 3900
See MaxofList() here:
http://allenbrowne.com/func-09.html

Access doesn't have any such functions, because having many repeating fields
is not a relational database design.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"MLH" <CR**@NorthState.netwrote in message
news:d2********************************@4ax.com...
Is there any built-in FN for returning largest value
in a group of say 2 - 10 values? Lets say I want
a FN something like MaxVal(5, 7, 9, 3, 12) or
perhaps MaxVal(79,34). I would wanna see
return value of 12 and 79 respectively.

What's simplest way to do that in A97?
Jul 17 '08 #2
JvC
Put the values in an array, and bubble sort it. I found the following
BubbleSort routine online. ToSort is your array of values. You may find
one you like more!

Sub BubbleSort(ToSort As Variant, Optional SortAscending As Boolean =
True)
' Chris Rae's VBA Code Archive - http://chrisrae.com/vba
' By Chris Rae, 19/5/99. My thanks to
' Will Rickards and Roemer Lievaart
' for some fixes.
Dim AnyChanges As Boolean
Dim BubbleSort As Long
Dim SwapFH As Variant
Do
AnyChanges = False
For BubbleSort = LBound(ToSort) To UBound(ToSort) - 1
If (ToSort(BubbleSort) ToSort(BubbleSort + 1) And
SortAscending) _
Or (ToSort(BubbleSort) < ToSort(BubbleSort + 1) And Not
SortAscending) Then
' These two need to be swapped
SwapFH = ToSort(BubbleSort)
ToSort(BubbleSort) = ToSort(BubbleSort + 1)
ToSort(BubbleSort + 1) = SwapFH
AnyChanges = True
End If
Next BubbleSort
Loop Until Not AnyChanges
End Sub
After serious thinking MLH wrote :
Is there any built-in FN for returning largest value
in a group of say 2 - 10 values? Lets say I want
a FN something like MaxVal(5, 7, 9, 3, 12) or
perhaps MaxVal(79,34). I would wanna see
return value of 12 and 79 respectively.

What's simplest way to do that in A97?

Jul 17 '08 #3
JvC
I like Allen's routine better!

JvC explained :
Put the values in an array, and bubble sort it. I found the following
BubbleSort routine online. ToSort is your array of values. You may find one
you like more!

Sub BubbleSort(ToSort As Variant, Optional SortAscending As Boolean = True)
' Chris Rae's VBA Code Archive - http://chrisrae.com/vba
' By Chris Rae, 19/5/99. My thanks to
' Will Rickards and Roemer Lievaart
' for some fixes.
Dim AnyChanges As Boolean
Dim BubbleSort As Long
Dim SwapFH As Variant
Do
AnyChanges = False
For BubbleSort = LBound(ToSort) To UBound(ToSort) - 1
If (ToSort(BubbleSort) ToSort(BubbleSort + 1) And
SortAscending) _
Or (ToSort(BubbleSort) < ToSort(BubbleSort + 1) And Not
SortAscending) Then
' These two need to be swapped
SwapFH = ToSort(BubbleSort)
ToSort(BubbleSort) = ToSort(BubbleSort + 1)
ToSort(BubbleSort + 1) = SwapFH
AnyChanges = True
End If
Next BubbleSort
Loop Until Not AnyChanges
End Sub
After serious thinking MLH wrote :
>Is there any built-in FN for returning largest value
in a group of say 2 - 10 values? Lets say I want
a FN something like MaxVal(5, 7, 9, 3, 12) or
perhaps MaxVal(79,34). I would wanna see
return value of 12 and 79 respectively.

What's simplest way to do that in A97?

Jul 17 '08 #4
MLH
Well, I don't know about the serious thinking part
of it, but here's where I was headed...
Function BiggestThing(a As Variant, b As Variant, Optional c As
Variant, Optional d As Variant, _
Optional e As Variant, Optional f As Variant, Optional g As Variant,
Optional h As Variant, _
Optional i As Variant, Optional j As Variant, Optional k As Variant,
Optional l As Variant, _
Optional m As Variant, Optional n As Variant, Optional o As Variant,
Optional p As Variant, _
Optional q As Variant, Optional r As Variant, Optional s As Variant,
Optional t As Variant) As Variant
'************************************************* ****************************************
' Idea here is to accept up to 20 values and return the biggest one,
' using the default sorting method set up in Access.
'************************************************* ****************************************
On Error GoTo Err_BiggestThing

100 Dim arr1 As Variant
120 Dim i2 As Integer, j2 As Integer, k2 As Integer

140 arr1 = Array(a, b, c, d, e, f, g, h, i, j, l, m, n, o, p, q, r, s,
t)
'160 i2 = arr1(0)
180 j2 = arr1(0)
200 For k2 = 1 To UBound(arr1)
220 If IsNull(arr1(k2)) Then Exit For
240 If arr1(k2) j2 Then j2 = arr1(k2)
260 Next
280 Debug.Print j2

It was kind-a-workin' ... But in the loop, when I
encountered the first Null array value - for some
reason the Exit For is not catching it. Can you
figure why?

I'm gonna have a look now at both your suggestion
and Allens. Thx 4 the feedback.


On Thu, 17 Jul 2008 07:10:33 -0700, JvC <jo******@earthlink.net>
wrote:
>Put the values in an array, and bubble sort it. I found the following
BubbleSort routine online. ToSort is your array of values. You may find
one you like more!

Sub BubbleSort(ToSort As Variant, Optional SortAscending As Boolean =
True)
' Chris Rae's VBA Code Archive - http://chrisrae.com/vba
' By Chris Rae, 19/5/99. My thanks to
' Will Rickards and Roemer Lievaart
' for some fixes.
Dim AnyChanges As Boolean
Dim BubbleSort As Long
Dim SwapFH As Variant
Do
AnyChanges = False
For BubbleSort = LBound(ToSort) To UBound(ToSort) - 1
If (ToSort(BubbleSort) ToSort(BubbleSort + 1) And
SortAscending) _
Or (ToSort(BubbleSort) < ToSort(BubbleSort + 1) And Not
SortAscending) Then
' These two need to be swapped
SwapFH = ToSort(BubbleSort)
ToSort(BubbleSort) = ToSort(BubbleSort + 1)
ToSort(BubbleSort + 1) = SwapFH
AnyChanges = True
End If
Next BubbleSort
Loop Until Not AnyChanges
End Sub
After serious thinking MLH wrote :
>Is there any built-in FN for returning largest value
in a group of say 2 - 10 values? Lets say I want
a FN something like MaxVal(5, 7, 9, 3, 12) or
perhaps MaxVal(79,34). I would wanna see
return value of 12 and 79 respectively.

What's simplest way to do that in A97?
Jul 17 '08 #5
MLH
Darn straight! You are right. Allen's FN's are awesome.
I wasn't familiar with the ParamArray thingie. Allen's put
some great solutions out on this forum over the years.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Thu, 17 Jul 2008 07:11:58 -0700, JvC <jo******@earthlink.net>
wrote:
>I like Allen's routine better!

JvC explained :
>Put the values in an array, and bubble sort it. I found the following
BubbleSort routine online. ToSort is your array of values. You may find one
you like more!

Sub BubbleSort(ToSort As Variant, Optional SortAscending As Boolean = True)
' Chris Rae's VBA Code Archive - http://chrisrae.com/vba
' By Chris Rae, 19/5/99. My thanks to
' Will Rickards and Roemer Lievaart
' for some fixes.
Dim AnyChanges As Boolean
Dim BubbleSort As Long
Dim SwapFH As Variant
Do
AnyChanges = False
For BubbleSort = LBound(ToSort) To UBound(ToSort) - 1
If (ToSort(BubbleSort) ToSort(BubbleSort + 1) And
SortAscending) _
Or (ToSort(BubbleSort) < ToSort(BubbleSort + 1) And Not
SortAscending) Then
' These two need to be swapped
SwapFH = ToSort(BubbleSort)
ToSort(BubbleSort) = ToSort(BubbleSort + 1)
ToSort(BubbleSort + 1) = SwapFH
AnyChanges = True
End If
Next BubbleSort
Loop Until Not AnyChanges
End Sub
After serious thinking MLH wrote :
>>Is there any built-in FN for returning largest value
in a group of say 2 - 10 values? Lets say I want
a FN something like MaxVal(5, 7, 9, 3, 12) or
perhaps MaxVal(79,34). I would wanna see
return value of 12 and 79 respectively.

What's simplest way to do that in A97?
Jul 17 '08 #6
MLH
Awesome help. Hat's off to you, Allen. Thx.
xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
On Thu, 17 Jul 2008 22:07:12 +0800, "Allen Browne"
<Al*********@SeeSig.Invalidwrote:
>See MaxofList() here:
http://allenbrowne.com/func-09.html

Access doesn't have any such functions, because having many repeating fields
is not a relational database design.
Jul 17 '08 #7
MLH <CR**@NorthState.netwrote in
news:a7********************************@4ax.com:
Darn straight! You are right. Allen's FN's are awesome.
I wasn't familiar with the ParamArray thingie.
What would be the advantage of using a parameter array rather than a single
array? Which method would be easier to call from other code?
Jul 17 '08 #8
MLH
On Thu, 17 Jul 2008 21:49:06 GMT, lyle fairfield <ly******@yah00.ca>
wrote:
>MLH <CR**@NorthState.netwrote in
news:a7********************************@4ax.com :
>Darn straight! You are right. Allen's FN's are awesome.
I wasn't familiar with the ParamArray thingie.

What would be the advantage of using a parameter array rather than a single
array? Which method would be easier to call from other code?
I guess it's the idea that you can have as many or as few
arguments as you wish. I could have, say, written the procedure
with 20 arguments in a single array. But then, 6-weeks from next
Tuesday, I might have needed to feed a 30-item list to the FN.
There's an element of elegance in the simplicity of his FN's that
I like too. I think the ease of calling either method is the same.
Jul 18 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: news1.on.sympatico.ca | last post by:
what is the literal for the largest character value in java? ie. 111 in binary is representing 7 (4+2+1) <-- this is 3 bit now java is 32 or 64 bit what is the largest character value ? ...
3
by: Dave | last post by:
Hello all, Suppose you have an unsigned integral type T. It's not one of the built-in types, but rather typedefed off of one of the built-in unsigned integral types (but we don't know which...
20
by: Rajesh | last post by:
Hello Everybody, Can anybody help me to write a C program for finding the second largest element in an array. without using any sort algo. The array may conatin duplicate elements. The algo...
19
by: ramu | last post by:
Hi, I have, suppose 1000 numbers, in a file. I have to find out 5 largest numbers among them without sorting. Can you please give me an efficient idea to do this? My idea is to put those numbers...
3
by: HEMH6 | last post by:
Who can help solve this problem??? Finding the Largest Value (a) write a function, largest(), that returns the largest value in a signed integer array. The array and its size are passed as...
25
by: Subra | last post by:
Hi, What is the best way to find the 1000 largest numbers from the file having hell lot of entries ? Can you please help me to find out the way ? Do I need to go for B+ trees ?? Please help,...
38
by: bele_harshad2006 | last post by:
how can i pick up largest no from 5 rows by 5 column matrix????
3
by: akselo | last post by:
Does anyone know a good way to compare several columns and return the largest value, somewhat like what MAX does for a single column?
6
by: Davy | last post by:
Hi all, I have a dictionary with n elements, and I want to get the m(m<=n) keys with the largest values. For example, I have dic that includes n=4 elements, I want m=2 keys have the largest...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.