473,325 Members | 2,442 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,325 software developers and data experts.

determine the maximum ubound of multiple arrays in a clean fashion

I have a number of arrays that are populated with database values. I
need to determine which array has the highest ubound out of all the
arrays. The array size will always change based on the database
record. Therefore, I need to be able to throw the arrays into a
function that will automatically determine the highest ubound array.
I was wondering if anyone might have a clean function that can do
this. I have created a function that works but there must be a simple
and more intuitive way to do this.

Any help would be greatly appreciated.

My example

Private Sub Command1_Click()
'these will always vary
Dim array1(15)
Dim array2(20)
Dim array3(27)
Dim array4(37)
Dim array5(7)

Dim myfinalstring

myfinalstring = checkupper(array1, array2, array3, array4, array5)

MsgBox myfinalstring


End Sub

Public Function checkupper(ByRef array1() As Variant, ByRef array2()
As Variant, ByRef array3() As Variant, ByRef array4() As Variant,
ByRef array5() As Variant) As String
If UBound(array1) > UBound(array2) And UBound(array1) > UBound(array3)
And UBound(array1) > UBound(array4) And UBound(array1) >
UBound(array5) Then

checkupper = "array1 is the highest"
Exit Function

End If

If UBound(array2) > UBound(array1) And UBound(array2) > UBound(array3)
And UBound(array2) > UBound(array4) And UBound(array2) >
UBound(array5) Then

checkupper = "array2 is the highest"
Exit Function

End If

If UBound(array3) > UBound(array1) And UBound(array3) > UBound(array2)
And UBound(array3) > UBound(array4) And UBound(array3) >
UBound(array5) Then

checkupper = "array3 is the highest"
Exit Function

End If

If UBound(array4) > UBound(array1) And UBound(array4) > UBound(array2)
And UBound(array4) > UBound(array3) And UBound(array4) >
UBound(array5) Then

checkupper = "array4 is the highest"
Exit Function

End If

If UBound(array5) > UBound(array1) And UBound(array5) > UBound(array2)
And UBound(array5) > UBound(array3) And UBound(array5) >
UBound(array4) Then

checkupper = "array5 is the highest"
Exit Function

End If

End Function
Jul 17 '05 #1
2 5066
"Jason" <jf******@yahoo.com> wrote in message
news:ec*************************@posting.google.co m...
I have a number of arrays that are populated with database values. I
need to determine which array has the highest ubound out of all the
arrays. The array size will always change based on the database
record. Therefore, I need to be able to throw the arrays into a
function that will automatically determine the highest ubound array.
I was wondering if anyone might have a clean function that can do
this. I have created a function that works but there must be a simple
and more intuitive way to do this.

How about a function that, given the same number of arrays, works like this:

Function HighestArray (array1, array2, array3, array4, array5) As Byte
Dim HighestUbound As Integer
Let HighestArray = 1
Let HighestUbound = Ubound(array1)
If Ubound(array2)>HighestUbound Then
HighestArray = 2
HighestUbound = Ubound(array2)
End If
If Ubound(array3)>HighestUbound Then
HighestArray = 3
HighestUbound = Ubound(array3)
End If
If Ubound(array4)>HighestUbound Then
HighestArray = 4
HighestUbound = Ubound(array4)
End If
If Ubound(array5)>HighestUbound Then
HighestArray = 5
HighestUbound = Ubound(array5)
End If
End Function

This basically keeps track of the highest array, and even the number of
entries in it if that's what you're after, too. I don't know if it's cleaner
or easier, but it looks logical.

Anyone else like to compare the functions?

--
QuickHare
(Qu**********@HEREHotmail.com)
Remove the NOT and HERE to E-Mail direct.
Enleve les NOT et HERE á E-Mail moi directement.

Jul 17 '05 #2
> Anyone else like to compare the functions?

Ahhh, a challenge...<g> Okay, here's my function:

Function HighestArray(ParamArray Arrays() As Variant) As Long
Dim X As Integer
Dim HighestUBound As Long
For X = 0 To UBound(Arrays)
If UBound(Arrays(X)) > HighestUBound Then
HighestUBound = UBound(Arrays(X))
HighestArray = X + 1
End If
Next
End Function

This function allows the number of arrays to be compared to vary (rather
that be fixed beforehand, 5 in the example you provided). As with your
function, this one identifies the array by its "count" number in the
argument list (1 for the first array, 2 for the second, and so on). I'm
thinking that to make use of the returned index (from either your function
or mine), the OP will have to use a Select Case block to read the returned
index value and identify the array's data source from it.

Rick - MVP


"QuickHare" <Qu**********@HEREHotmail.com> wrote in message
news:bl************@athena.ex.ac.uk...
"Jason" <jf******@yahoo.com> wrote in message
news:ec*************************@posting.google.co m...
I have a number of arrays that are populated with database values. I
need to determine which array has the highest ubound out of all the
arrays. The array size will always change based on the database
record. Therefore, I need to be able to throw the arrays into a
function that will automatically determine the highest ubound array.
I was wondering if anyone might have a clean function that can do
this. I have created a function that works but there must be a simple
and more intuitive way to do this. How about a function that, given the same number of arrays, works like

this:
Function HighestArray (array1, array2, array3, array4, array5) As Byte
Dim HighestUbound As Integer
Let HighestArray = 1
Let HighestUbound = Ubound(array1)
If Ubound(array2)>HighestUbound Then
HighestArray = 2
HighestUbound = Ubound(array2)
End If
If Ubound(array3)>HighestUbound Then
HighestArray = 3
HighestUbound = Ubound(array3)
End If
If Ubound(array4)>HighestUbound Then
HighestArray = 4
HighestUbound = Ubound(array4)
End If
If Ubound(array5)>HighestUbound Then
HighestArray = 5
HighestUbound = Ubound(array5)
End If
End Function

This basically keeps track of the highest array, and even the number of
entries in it if that's what you're after, too. I don't know if it's cleaner or easier, but it looks logical.

Anyone else like to compare the functions?

--
QuickHare
(Qu**********@HEREHotmail.com)
Remove the NOT and HERE to E-Mail direct.
Enleve les NOT et HERE á E-Mail moi directement.

Jul 17 '05 #3

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

Similar topics

5
by: JT | last post by:
how do i determine how many items are in an array? the following code creates an array of values each time a space is found in a name field. the problem is that sometimes names have middle...
11
by: Ohaya | last post by:
Hi, I'm trying to understand a situation where ASP seems to be "blocking" of "queuing" requests. This is on a Win2K Advanced Server, with IIS5. I've seen some posts (e.g.,...
9
by: Till Crueger | last post by:
Hi, I have to implement some simple sorting algorithm. I am NOT asking for you to do my homework, but my question is rather on how to store the integers. I recall reading once in here that there...
2
by: Starbuck | last post by:
Hi All In one of my converted (VB6 to VB.Net) apps I have managed to remove all instances of - Imports Microsoft.VisualBasic - except for one form which raises errors in regard to LBound and...
4
by: JR | last post by:
I may have posted a blank post accidentally. Sorry I am coming over to VB.NET from C++/C# and am confused about the UBound function. Example code: Dim i As Integer Dim myarray(6) As...
6
by: Homer J. Simpson | last post by:
Hi all, I have enough experience with HTML/classic ASP to get by, and I'm trying to learn ASP.NET. Traditionally, I've taken the habit of breaking out extra-long CSS files into multiple,...
13
by: Eric IsWhoIAm | last post by:
I have four tables created so far: Courses, Instructors, Courses and Instructors (which shows the Course and Instructor Name fields, but holds their IDs since those are the keys), and Students....
7
by: Brent | last post by:
I'm trying to figure out how to iterate over an array that would send a series of XMLHttp requests. I'd like to have each request finish before the next one begins, but I believe that this is not...
18
by: raylopez99 | last post by:
The maximum int for an array on my machine (a Pentium IV with 2 GB RAM) is < 330 Million...before you get an "out of memory" exception. I simply filled an array of this size with ints...I got as...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.