mikarei
asked on
count number of elements in an array
how do i count the number of elements in an array?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The contents of an array make no difference on the number of elements !!
just use the code above to get the number of elements in ur array.
Regards,
just use the code above to get the number of elements in ur array.
Regards,
This code:
Response.Write UBound(yourArrayVariableNa me)
Returns the highest numerical index you can use to refer to a value in your array. This means that yourArrayVariableName(UBou nd(yourArr ayVariable Name)) returns the last element in the array.
_____
This code:
Response.Write UBound(yourArrayVariableNa me) + 1
Returns the number of elements in your array.
_____
In ASP, data types in arrays are transparent and doesn't matter much. That's why it is possible to have multiple data types in a single array variable: Array(1, "Hi", Array("0.5", 1.25), objectVariable). Variants! Variants! Variants!
This code will loop through your array:
For i = LBound(yourArrayVariableNa me) To UBound(yourArrayVariableNa me)
Response.Write yourArrayVariableName(i)
Next
Have fun.
Response.Write UBound(yourArrayVariableNa
Returns the highest numerical index you can use to refer to a value in your array. This means that yourArrayVariableName(UBou
_____
This code:
Response.Write UBound(yourArrayVariableNa
Returns the number of elements in your array.
_____
In ASP, data types in arrays are transparent and doesn't matter much. That's why it is possible to have multiple data types in a single array variable: Array(1, "Hi", Array("0.5", 1.25), objectVariable). Variants! Variants! Variants!
This code will loop through your array:
For i = LBound(yourArrayVariableNa
Response.Write yourArrayVariableName(i)
Next
Have fun.
Are you looking to determine how many elements of your arrays have values stored in them? If so:
dim NumElements
NumElements =0
For i = LBound(ArrayName) To UBound(ArrayName)
if Trim(ArrayName(i)) <> "" then
NumElements = NumElements +1
end if
Next
msgbox NumElements
dim NumElements
NumElements =0
For i = LBound(ArrayName) To UBound(ArrayName)
if Trim(ArrayName(i)) <> "" then
NumElements = NumElements +1
end if
Next
msgbox NumElements
I don't really get your question.
The type of variable doesn't affect the amount of elements.
Note: Strings in ASP are variables, not arrays.
But if you have more than one dimension in the array, you can use:
ubound(array,dimension)
lbound(array,dimension)
eg:
dim a(4 to 20,5 to 8)
as1 = ubound(a,1)-lbound(a,1) +1
as2 = ubound(a,2)-lbound(a,2) +1
arraysize = as1 * as2
---
Erez Sh.
The type of variable doesn't affect the amount of elements.
Note: Strings in ASP are variables, not arrays.
But if you have more than one dimension in the array, you can use:
ubound(array,dimension)
lbound(array,dimension)
eg:
dim a(4 to 20,5 to 8)
as1 = ubound(a,1)-lbound(a,1) +1
as2 = ubound(a,2)-lbound(a,2) +1
arraysize = as1 * as2
---
Erez Sh.
mikarei,
Were any of these comments helpful? If so, please select one as an answer.
Fritz the Blank
Were any of these comments helpful? If so, please select one as an answer.
Fritz the Blank
mikarei,
Some of these questions have been open for some time, and records indicate you logged in as recently as a week ago. Please resolve them appropriately as soon as possible. Continued disregard of your open questions will result in the force/acceptance of a comment as an answer; other actions affecting your account may also be taken. I will revisit these questions in approximately seven (7) days.
https://www.experts-exchange.com/jsp/qShow.jsp?ta=asp&qid=20183550
https://www.experts-exchange.com/jsp/qShow.jsp?ta=asp&qid=20192103
https://www.experts-exchange.com/jsp/qShow.jsp?ta=asp&qid=20194210
https://www.experts-exchange.com/jsp/qShow.jsp?ta=asp&qid=20199602
https://www.experts-exchange.com/jsp/qShow.jsp?ta=asp&qid=20219426
https://www.experts-exchange.com/jsp/qShow.jsp?ta=asp&qid=20222147
https://www.experts-exchange.com/jsp/qShow.jsp?ta=asp&qid=20229745
https://www.experts-exchange.com/jsp/qShow.jsp?ta=coldfusion&qid=20193133
https://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20194224
https://www.experts-exchange.com/jsp/qShow.jsp?ta=javascript&qid=20169233
https://www.experts-exchange.com/jsp/qShow.jsp?ta=javascript&qid=20174790
https://www.experts-exchange.com/jsp/qShow.jsp?ta=javascript&qid=20175609
https://www.experts-exchange.com/jsp/qShow.jsp?ta=javascript&qid=20178005
https://www.experts-exchange.com/jsp/qShow.jsp?ta=javascript&qid=20178579
https://www.experts-exchange.com/jsp/qShow.jsp?ta=javascript&qid=20190066
https://www.experts-exchange.com/jsp/qShow.jsp?ta=javascript&qid=20203006
https://www.experts-exchange.com/jsp/qShow.jsp?ta=javascript&qid=20206006
https://www.experts-exchange.com/jsp/qShow.jsp?ta=frontpage&qid=20192026
https://www.experts-exchange.com/jsp/qShow.jsp?ta=php&qid=20251453
https://www.experts-exchange.com/jsp/qShow.jsp?ta=perl&qid=20168673
https://www.experts-exchange.com/jsp/qShow.jsp?ta=perl&qid=20234353
https://www.experts-exchange.com/jsp/qShow.jsp?ta=perl&qid=20237989
https://www.experts-exchange.com/jsp/qShow.jsp?ta=perl&qid=20257925
Please note that an Easy question is normally considered to be worth 50 points.
Thanks,
Netminder
Community Support Moderator
Experts Exchange
Some of these questions have been open for some time, and records indicate you logged in as recently as a week ago. Please resolve them appropriately as soon as possible. Continued disregard of your open questions will result in the force/acceptance of a comment as an answer; other actions affecting your account may also be taken. I will revisit these questions in approximately seven (7) days.
https://www.experts-exchange.com/jsp/qShow.jsp?ta=asp&qid=20183550
https://www.experts-exchange.com/jsp/qShow.jsp?ta=asp&qid=20192103
https://www.experts-exchange.com/jsp/qShow.jsp?ta=asp&qid=20194210
https://www.experts-exchange.com/jsp/qShow.jsp?ta=asp&qid=20199602
https://www.experts-exchange.com/jsp/qShow.jsp?ta=asp&qid=20219426
https://www.experts-exchange.com/jsp/qShow.jsp?ta=asp&qid=20222147
https://www.experts-exchange.com/jsp/qShow.jsp?ta=asp&qid=20229745
https://www.experts-exchange.com/jsp/qShow.jsp?ta=coldfusion&qid=20193133
https://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20194224
https://www.experts-exchange.com/jsp/qShow.jsp?ta=javascript&qid=20169233
https://www.experts-exchange.com/jsp/qShow.jsp?ta=javascript&qid=20174790
https://www.experts-exchange.com/jsp/qShow.jsp?ta=javascript&qid=20175609
https://www.experts-exchange.com/jsp/qShow.jsp?ta=javascript&qid=20178005
https://www.experts-exchange.com/jsp/qShow.jsp?ta=javascript&qid=20178579
https://www.experts-exchange.com/jsp/qShow.jsp?ta=javascript&qid=20190066
https://www.experts-exchange.com/jsp/qShow.jsp?ta=javascript&qid=20203006
https://www.experts-exchange.com/jsp/qShow.jsp?ta=javascript&qid=20206006
https://www.experts-exchange.com/jsp/qShow.jsp?ta=frontpage&qid=20192026
https://www.experts-exchange.com/jsp/qShow.jsp?ta=php&qid=20251453
https://www.experts-exchange.com/jsp/qShow.jsp?ta=perl&qid=20168673
https://www.experts-exchange.com/jsp/qShow.jsp?ta=perl&qid=20234353
https://www.experts-exchange.com/jsp/qShow.jsp?ta=perl&qid=20237989
https://www.experts-exchange.com/jsp/qShow.jsp?ta=perl&qid=20257925
Please note that an Easy question is normally considered to be worth 50 points.
Thanks,
Netminder
Community Support Moderator
Experts Exchange
Netminder,
Here's an idea:
Information like this (amount of unranked questions) can be shown along with the user.
That way we can know who we are dealing with, without harvesting his profile.
Erez Sh.
Here's an idea:
Information like this (amount of unranked questions) can be shown along with the user.
That way we can know who we are dealing with, without harvesting his profile.
Erez Sh.
erezsh,
If you click on the user's name, you'll see their question history. Your suggestion has been made as a possible upgrade to the site, but I can't honestly tell you when or even if it will happen.
As Moderators, we do not make it a practice to automatically show a questioner's history when we ask them to clean up their open questions, but I will say that there are Experts out there who refrain from commenting in questions BECAUSE of the number of open questions a User has.
In this particular case, the User has yet to respond to my request; if he/she doesn't by my deadline, then I will deal with the list of open questions on my own, and will most likely ask Admin to suspend the account.
Netminder
Community Support Moderator
Experts Exchange
If you click on the user's name, you'll see their question history. Your suggestion has been made as a possible upgrade to the site, but I can't honestly tell you when or even if it will happen.
As Moderators, we do not make it a practice to automatically show a questioner's history when we ask them to clean up their open questions, but I will say that there are Experts out there who refrain from commenting in questions BECAUSE of the number of open questions a User has.
In this particular case, the User has yet to respond to my request; if he/she doesn't by my deadline, then I will deal with the list of open questions on my own, and will most likely ask Admin to suspend the account.
Netminder
Community Support Moderator
Experts Exchange
Admin notified of user neglect. Force/accepted by
Netminder
Community Support Moderator
Experts Exchange
Netminder
Community Support Moderator
Experts Exchange
ASKER