473,799 Members | 3,107 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1622
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(RT rim(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(RT rim(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_p osition Then
highest_array_p osition = array_position_ just_defined

with highest_array_p osition 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(RT rim(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_p osition Then
: highest_array_p osition = array_position_ just_defined

: with highest_array_p osition initialized to -1 for the empty array.

Nov 13 '05 #7
"Jozef" <SP**********@t elus.net> wrote in
news:w1Lue.1786 745$6l.247118@p d7tw2no:
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**********@t elus.net> wrote in message
news:w1Lue.1786 745$6l.247118@p d7tw2no...
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

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

Similar topics

3
1715
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 type="checkbox" name="delete"> If I then submit the form, the array $delete is the only one which isn't indexed by its order on the form.
9
1966
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 he only enter values into the first four. I need to ALWAYS extract the final or last field that has a value. In the example below this would be PriceField5 which has a value of $162,000. The user stopped at this field and left the rest blank.
21
13486
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 getting second highest value in an integer array. One method I know of is to make the 1st pass through the array and find the highest number. In the second pass we can find the highest number which is less than the number we obtained in the 1st pass.
6
24341
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 the Sort Method ( ) but doesn't seem like it can do the job or am i missing something?
7
3358
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
7722
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
8813
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
9541
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10231
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7565
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6805
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4141
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.