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

Determining the highest array value without cycling through

Hello,

Is there an easy way to determine the highest point in an array that
contains a value? I'm dimensioning an array to hold up to 255 items, but if
it only contains three, I don't want to cycle through all 255 if that's
possible.

any ideas?
Thanks!
Nov 13 '05 #1
12 1583
Jozef wrote:
Hello,

Is there an easy way to determine the highest point in an array that
contains a value? I'm dimensioning an array to hold up to 255 items, but if
it only contains three, I don't want to cycle through all 255 if that's
possible.


Yes, you could create a separate counter variable to let you know how may of the array
slots are populated. Or you could use a marker in the slot after the last valid entry.

You could also dynamically resize the array using the Redim statement but there may be
performance issues to consider.

--
'---------------
'John Mishefske
'---------------
Nov 13 '05 #2
rkc
Jozef wrote:
Hello,

Is there an easy way to determine the highest point in an array that
contains a value?
Not unless you were keeping track while the array was being
populated.
I'm dimensioning an array to hold up to 255 items, but if
it only contains three, I don't want to cycle through all 255 if
that's possible.


It's possible to check for a value and exit the loop if there isn't
one. Something you should be doing any way if you're performing
some operation on each value as you cycle through them.

Nov 13 '05 #3
My idea (for a string array, a) is

UBound(Split(RTrim(Join(a))))

Please, let me know how and if this works as it's "total air" code.

Nov 13 '05 #4
ly******@yahoo.ca <ly******@yahoo.ca> wrote:
: My idea (for a string array, a) is

: UBound(Split(RTrim(Join(a))))

: Please, let me know how and if this works as it's "total air" code.
Does this mean that this is invalid?

Dim Aray(26) as String
Aray(19) = "This "
Aray(8) = "is "
Aray(12) = "my "
Aray(0) = "array."

This 26 element array with four defined elements has its last
defined element at place 20
A separate counter seems like the safest route to me, updated like
this:

If array_position_just_defined > highest_array_position Then
highest_array_position = array_position_just_defined

with highest_array_position initialized to -1 for the empty array.

--thelma
Nov 13 '05 #5
rkc
ly******@yahoo.ca wrote:
My idea (for a string array, a) is

UBound(Split(RTrim(Join(a))))

Well I'll be dipped in pancake batter.
Nov 13 '05 #6
Thelma Lubkin <th****@alpha2.csd.uwm.edu> wrote:
: Dim Aray(26) as String
: Aray(19) = "This "
: Aray(8) = "is "
: Aray(12) = "my "
: Aray(0) = "array."

: This 26 element array with four defined elements has its last
: defined element at place 20

arghh... 19
--thelma

: A separate counter seems like the safest route to me, updated like
: this:

: If array_position_just_defined > highest_array_position Then
: highest_array_position = array_position_just_defined

: with highest_array_position initialized to -1 for the empty array.

Nov 13 '05 #7
"Jozef" <SP**********@telus.net> wrote in
news:w1Lue.1786745$6l.247118@pd7tw2no:
Is there an easy way to determine the highest point in an array
that contains a value? I'm dimensioning an array to hold up to
255 items, but if it only contains three, I don't want to cycle
through all 255 if that's possible.


Why do you have blank entries in your array?

If you need to have a certain number of parameters with or without
values, what about using the array in conjunction with a collection,
and you'd use the collection to manage which items had values?

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #8


Thelma Lubkin wrote:
Thelma Lubkin <th****@alpha2.csd.uwm.edu> wrote:
: Dim Aray(26) as String
: Aray(19) = "This "
: Aray(8) = "is "
: Aray(12) = "my "
: Aray(0) = "array."

: This 26 element array with four defined elements has its last
: defined element at place 20

arghh... 19
--thelma


Huh?

Nov 13 '05 #9
Thanks for your help folks. I'm already using a counter, I was just curious
if there was a single function I could call (there should be,
Microsoft...are you listening?) Something like MaxArr(MyArray) ....tha'd be
good.
"Jozef" <SP**********@telus.net> wrote in message
news:w1Lue.1786745$6l.247118@pd7tw2no...
Hello,

Is there an easy way to determine the highest point in an array that
contains a value? I'm dimensioning an array to hold up to 255 items, but
if it only contains three, I don't want to cycle through all 255 if that's
possible.

any ideas?
Thanks!

Nov 13 '05 #10
ly******@yahoo.ca wrote:

Thelma Lubkin wrote:
Thelma Lubkin <th****@alpha2.csd.uwm.edu> wrote:
: Dim Aray(26) as String
: Aray(19) = "This "
: Aray(8) = "is "
: Aray(12) = "my "
: Aray(0) = "array."

: This 26 element array with four defined elements has its last
: defined element at place 20

arghh... 19
--thelma

Huh?


Right first time, element numbered 19 is place 20 if it's zero based :-)

--
[OO=00=OO]
Nov 13 '05 #11
Trevor Best <no****@besty.org.uk> wrote:
: ly******@yahoo.ca wrote:
:>
:> Thelma Lubkin wrote:
:>
:>>Thelma Lubkin <th****@alpha2.csd.uwm.edu> wrote:
:>>: Dim Aray(26) as String
:>>: Aray(19) = "This "
:>>: Aray(8) = "is "
:>>: Aray(12) = "my "
:>>: Aray(0) = "array."
:>>
:>>: This 26 element array with four defined elements has its last
:>>: defined element at place 20
:>>
:>> arghh... 19
:>> --thelma
:>>
:>
:>
:> Huh?
:>

: Right first time, element numbered 19 is place 20 if it's zero based :-)

Yes. I was thinking of 'place' in the sense of the
counter-number you'd use in a 'while i <=' type loop,
but it is of course the 20'th 'physical' place in the array.
--thelma
: --
: [OO=00=OO]
Nov 13 '05 #12
I think you have rightly implied that
UBound(Split(RTrim(Join(a))))
doesn't work when some of the elements (strings) have spaces. These
elements are counted twice.

Maybe this will help:

UBound(Split(RTrim(Join(a)))) - UBound(Filter(a, " ", True))

It gives 19 for your array. Does it work for every string array? I
doubt it but it might be something that could be developed further.

BTW it seems filter does not filter for the string given, but for any
occurrence of the string in any of the string elements, rather like a
wildcard. Thus it returns true for
" ab", and "a b" and "ab " and "a b", etc.

Nov 13 '05 #13

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

Similar topics

3
by: Nik Coughin | last post by:
I am having a problem with checkboxes... I have a number of blocks like this on my form: <input type="text" name="name" value="a name"> <input type="text" name="ddi" value="1234"> <input...
9
by: jason | last post by:
Access 2000 I need some help interogatting a table and extracting via ASP the final field in a row which has a value. In other words, I have a maximum of 10 fields but, at the user level he may...
21
by: Jaspreet | last post by:
I was working on some database application and had this small task of getting the second highes marks in a class. I was able to do that using subqueries. Just thinking what is a good way of...
6
by: Ada | last post by:
hello folks, is there a way to retrieve the highest value in the ArrayList? let say i have a value in the array: {1, 4, 15, 3, 7} it should return a value 15 as the result. i've looked at...
7
by: Jan | last post by:
Hi there, Is there a fast way to get the highest value from an array? I've got the array strStorage(intCounter) I tried something but it all and's to nothing If someone good helpme, TIA
17
by: rhitz1218 | last post by:
Hi, I'm trying to create a function that will sort a number's digits from highest to lowest. For example 1000 - will become 0001 or 1234 to 4321
3
by: =?Utf-8?B?cm9kY2hhcg==?= | last post by:
hey all, i have an int array and was just wondering if there is a way to get the highest value in the array? for instance, int myValues = new int { 0, 1, 2 } highest value is 2. thanks,
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: 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: 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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.