473,387 Members | 1,705 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,387 software developers and data experts.

Counting items in an array?

Hi all,

Ok - I appreciated I could probably just do this :

For Each item IN array

intCount = intCount + 1

Next

I figured there might be a better way in .net...

I stumbled across this :

array.GetLength(intCount)

etc

I have tried using it but it returns as zero each time - in my current
scenario there are 2 items in the array...

The code I am using is such :

aReturnCodes = Split(strReturnCode, ",") ' populates array
aReturnCodes.GetLength(intArrayItems) ' gets length of array
label3.text = intArrayItems ' displays to page

My string has the following text before it goes into the array

6,7,

Therefore I expect at least 2 elements in my array - quite possibly 3
because of the trailing comma (to be removed)

However the label displays 0 ??

Any ideas?

Regards
Rob
Nov 18 '05 #1
4 10422
GetLength expects the dimension as parameter (count of items in a
dimension). Did you try just Length property of the array itself?

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist

"Rob Meade" <ro**********@NOSPAMubht.swest.nhs.uk> wrote in message
news:O6**************@TK2MSFTNGP12.phx.gbl...
Hi all,

Ok - I appreciated I could probably just do this :

For Each item IN array

intCount = intCount + 1

Next

I figured there might be a better way in .net...

I stumbled across this :

array.GetLength(intCount)

etc

I have tried using it but it returns as zero each time - in my current
scenario there are 2 items in the array...

The code I am using is such :

aReturnCodes = Split(strReturnCode, ",") ' populates array
aReturnCodes.GetLength(intArrayItems) ' gets length of array
label3.text = intArrayItems ' displays to page

My string has the following text before it goes into the array

6,7,

Therefore I expect at least 2 elements in my array - quite possibly 3
because of the trailing comma (to be removed)

However the label displays 0 ??

Any ideas?

Regards
Rob

Nov 18 '05 #2
You probably want something like:

intArrayItems=aReturnCodes.Length which gives the total
number of elements in the array. As you've got a 1
dimensional array, this is fine.

GetLength returns the length of the array in a specific
dimension of that array (say you've got a 2 by 3 array,
Array.GetLength(0) might return '2' and Array.GetLength
(1) might return '3'

Think I've got that right... give it a whirl
-----Original Message-----
Hi all,

Ok - I appreciated I could probably just do this :

For Each item IN array

intCount = intCount + 1

Next

I figured there might be a better way in .net...

I stumbled across this :

array.GetLength(intCount)

etc

I have tried using it but it returns as zero each time - in my currentscenario there are 2 items in the array...

The code I am using is such :

aReturnCodes = Split(strReturnCode, ",") ' populates arrayaReturnCodes.GetLength(intArrayItems) ' gets length of arraylabel3.text = intArrayItems ' displays to page

My string has the following text before it goes into the array
6,7,

Therefore I expect at least 2 elements in my array - quite possibly 3because of the trailing comma (to be removed)

However the label displays 0 ??

Any ideas?

Regards
Rob
.

Nov 18 '05 #3

"Rob Meade" <ro**********@NOSPAMubht.swest.nhs.uk> wrote in message
news:O6**************@TK2MSFTNGP12.phx.gbl...
Hi all,

Ok - I appreciated I could probably just do this :

For Each item IN array

intCount = intCount + 1

Next

I figured there might be a better way in .net...

I stumbled across this :

array.GetLength(intCount)


array.GetLength does not return it's value in the "intCount" parameter you
supply.

for a single-dimension array, you can use array.Length, which gives the
total number of
elements in the array.
For a multi-dimension array, you can use array.GetLength(dimension) to get
the number
of elements in *that* dimension.

Hans Kesting
Nov 18 '05 #4
"Rob Meade" wrote ...

[..snip..]

Found out I was doing it wrong - the integer in brackets was supposed to
refer to the column in the array...

Regards

Rob
Nov 18 '05 #5

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

Similar topics

9
by: NiQ | last post by:
Hello every one, this is about an array of string and may be have done several time before but i need it and wasnt able to find it so here is the problem i have an array of strings with contains...
14
by: Mike N. | last post by:
Hello: I have a form that contains a multiple-select field that has 12 options in it. I would like the user to be able to select UP TO FOUR of those options. If they select more than four, I...
6
by: edwardfredriks | last post by:
I'm looking for a script that, instead of counting down, can "count up" from a given date. So the output should be something like "(xx) days since (date/event)" or "(date/event) was (xx) days ago"....
18
by: ChadDiesel | last post by:
I appreciate the help on this group. I know I've posted a lot here the last couple of weeks, but I was thrown into a database project at my work with very little Access experience. No other...
4
by: mb | last post by:
what is the best way to do this: In a game I want to a class called "Items". This class will have the game items public class Items { public int Chair public int Table . . .and so on . . .
21
by: StriderBob | last post by:
Situation : FormX is mdi child form containing 2 ListViews ListView1 contains a list of table names and 4 sub items with data about each table. ListView2 contains a list of the columns on each...
10
by: Tony Young | last post by:
Hi, I have an array of integer. I need to find the max of the 0th, 3th, 6th , 9th, ... elements in the array. I wonder if STL (standard template library) provides a way to manipulate only part...
14
by: Dan | last post by:
Is this discouraged?: for line in open(filename): <do something with line> That is, should I do this instead?: fileptr = open(filename) for line in fileptr: <do something with line>
4
by: frizzle | last post by:
Hi there, I have a function to create an array of all files in a certain folder, so i can display the structure. The actual function is below the message, as is an example of its output. As...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...
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...

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.