Tracker
 ASP PHP JavaScripts MySQL MS Access MSSQL VISUAL BASIC Subjects/Titles Post Text/Content
HOME    TRACKER    Visual Basic

# Number Of Elements In Array

## I wonder how I can see how many elements there are in an array, for example:dim array() as stringfor n=0 to ( int(10-2+1) * rnd + 2)array(n) = "Element"next nHow can I get the number of elements that have been created?

Number Of Elements In Array?
Is there a way in vb6 to find the number of array elements?

Anything similar to sizeof i can use?

Number Of Elements In Array
Hello, I need to know how to get the number of elements in an array.
Like Len(), but not with a string but with an array.
Anyone who could help me out?

Number Of Elements In An Array
I have an array (called arrName). This array is created by using Split on the contents of a textbox. My delimiter for the Split is a space.

Is there an easier way of telling how many elements are in this array without looping through it first and incrementing a counter?

The problem I'm having is between names like:

Ann Smith
Ann Marie Smith

In the first example Ann becomes the first name and Smith the last which is correct.

However, in my second example Ann becomes the first name and Marie becomes the last whereas it should be first name equals Ann Marie and last name equals Smith.

So, my though is if there are 3 elements then I will store the first two in strFirstName, but if there are only 2 elements then I will store just the first in strFirstName.

Number Of Elements In Array?
Hi,
I have this situation:
dim ar() as string
ar=somefunction()

question is how to get number of elements in ar array?

Thanks,

regard j

How To Get The Length Of Array And The Number Of Elements In Array
How to get the number of elements of array?

Finding The Number Of Elements In An Array
i am trying to fill a combo box with elements which is controlled by a for loop.

Is there a function to determine the number of elements in an array so that i can use this to control the number of times the for loop executes

EG

For i% = 1 To arraysize

Next i%

in the above example i need arraysize to control the foor loop and the items added to the combo box

thanks

Lisa

Return Number Of Elements In An Array
Im sure I've seen a functions somewhere that lets you specfiy a single dimension array and it will give you the number of elements without having to use a loop, can someone remind me what it is?

Number Of Individual Elements In Array
I have an array that has values from 0 to 255, how can i tell how many of each number are in the array?

How To Find The Number Of Elements In An Array?
Hi

I have a function which returns a string array. The number of elements vary each time it is called.

Can any one tell how i can get the number of index from the calling procedure?

Thanks

Number Of Elements In An Array {RE-RESOLVED}
I have a string something like this: "GC20012345_43598_E"

I need to make each part of that string a seperate element in an array, which I have done with the following:
VB Code:
Dim arrDocNumbers() As StringDim sString As StringsString = "GC20012345_43598_E"arrDocNumbers = Split(sString, "_")
Everything works fine. Now, based on the letter at the end, I populate a variable, with this:
VB Code:
Select Case arrDocNumbers(2)   Case "E"   sDocType = "EOB Documents"   Case "B"   sDocType = "Scanned Bills"End Select
Again, everything works fine. However, if the string does not contain a trailing _E or trailing _B (in other words, the string is simply GC20012345_43598), then I get a subscript out of range error. This is completely understandable as if the string is missing the final part, there will not be a arrDocNumbers(2).

So, my question is: how do I determine if my array has three elements (0 through 2), or just two elements (0 through 1)?

Count Number Of Array Elements
Hello

I read a file in with the following code:

Open file For Binary As #1
strBuff = Space(LOF(1))
Get #1, , strBuff
Close #1

I then read it into an array with this code:

reqList = Split(strBuff, vbCrLf)

reqList is defined earlier in the program:

Dim reqList() As String

What I would like to know is an easy way to find out how many elements the array has...each time the file could be a different size but it is always in the format:

text,text
text,text
text,text

Any suggestions?

Thanks a lot!

How Do You Find The Number Of Elements In An Array?
In VB6, how can you find the number of elements contained within an array?

I create the array using the Split() function, so there could be any number of elements.

Number Of Elements In A Dynamic Array
How do you find out the number of elements in a dynamic array? Pretty sure I saw a function to do it once...just don't remeber it.

And how do you reset a dynamic array? I mean, how do you delete all the elements? Just redim it?

Thanks

Counting The Number Of Elements In An Array...
Perhaps a simple question, bu can anyone tell me the simplist way to count the depth of my array ... like the count method in the collection class.

Do I have to loop through until an error is raised to determine how many of an array I have?

Counting Number Of Elements In An Array
I am reading employess names into a listbox using an array.

How can i count the number of names in the listbox and display the number i a box

this is how i am using the array

Edited by - artrite on 10/31/2004 1:44:00 AM

Find Number Of Array Elements ?
Hi all,

Is there any way to find whether an array is empty or it contains some elements ?

For ex.
Dim arr() as long

MsgBox UBound(arr) 'Throws subscript out of range error

At runtime the array will be passed as parameter to a function. The array may contain elements or may not contain any elements. Is there any way to find the array is empty ?

Thanks for the replies

How To Determine The Number Of Array Elements
how do I determine the number of array elements if I don't know it a the beginning and don't want to set a fixed number?

Number Of Elements In A Fixed-length Array?
when declaring an array, it must be set with a constant value. ie, you can not do it like this:
Code:
Dim arrayDeck(1 To x) As String

and modify the length of the array by changing the value of x

is there a way of checking the number of cells containing values in the array? for example, if the array is 96 cells long but only the first 67 contain a value...
if the array is 96 cells long and being depleted from the upper end to the lower end

UBound(arrayDeck) returns the length of the array, always being 96.

Max Number Of Elements
Is there a way to determine the total number of elements in an array?

Like if I did this:

Code:
Dim stuff As Variant
stuff = Split(Text1.Text,",")

that turns stuff into an array. Is there a way to return how many elements are in that array??

How To Get The Link Number Without Counting All Elements ?
Hi !
I'm wondering if there's a method or property applying to an HTML document element (DOM, isn't it ?) in order to get the link number (or the input number or ...) easily when clicking on it, without being obliged to count and identify every element ?
For instance, I'm able to get the url of the link just clicked in the browser with the following code :
MyDocument.activeElement.getAttribute("href")

LeIench.

Edited by - pramboz on 12/9/2005 7:14:07 AM

*RESOLVED* User Search With Variable Number Of Elements
I have (what I think is) a complex search requirement where the user is allowed to choose from five criteria, they may choose one element, all five elements or any combination in between.

I have queries built to find matches based on any one element, now I need to compare the resulting recordsets against each other to determine if any records match ALL the selected search elements.

HOW do you compare rec sets??? Note - all rec sets have the same 4 fields, so either all fields in the record match or the record is not a match at all.

Any help would be appreciated as I am past the deadline for completing this project and it's not looking good!

TIA,
MDS

Tell How Many Elements Are In An Array
How do i tell how many elements are in an array? The array is created by another function, so i dont know how many there are by defining them in the varible like you normally would. Thanks.

Max Elements In Array?
both my text books don't provide an answer. ty for ur help.

No. Of Elements In Array
Hi, i was just wondering if there is a easy way to find out the number of elements in an array.

# Of Elements In Array
I have an array that was created using the 'Filter' function from another array. I need to know how many elements were returned in this new array, and really don't know how to go about that...

Efficiency is an issue as the original array had thousands of elements, and there may be hundreds or even thousands in the new one as well.

Help!

Im stuck

I can split a text file to an array ok but I would like to add 10 empty lines or elements at the end of the array.

How do I do this?

Would I use vbcrlf or would I loop through the array and add the elements.

Open Cdlg.FileName For Binary As #intFileHandle 'Open the text file

text = Space(LOF(1))

Get #1, , text

array = Split(text, vbCrLf)

thx for any help

How Do You Know How Many Elements An Array Has...?
I know this is probably a really noob question... but how...?
I thought that I remember myself being able to use array.UBound() or something like that, but it doesn't work anymore.. or maybe I just remember wrong... So how do you determine the length on an array?

How To Know Whether Array Is Having Any Elements Or Not?
Hi all

can any one tell "How to know whether array is having any elements or
not?"

thanks & regards,
Sridhar CS

How Many Elements In An Array
Hi!
I have a function that takes an array of integers as argument. This is a dynamic array so I don´t know how may elements in this array.
How do I find that out?
Jen

Delete All Elements Array
Hallo,
there is any way to delete all the elements of an array.
I have a global array:

Global lRow(excelLineNumber) As String

I try with:
reDim lRow(0)
reDim lRow

But it doesn't function.

Thanks.

Detecting Whether An Array Has Elements
I have an array, that I have dimensioned with zero elements:

Dim Cat()

I need to know if the user has loaded data into the array (causing it to be redimensioned to some, UNKNOWN size) before I call certain subroutines. I've tried:

If Cat()....

If Cat() = NULL....

If Ubound(Cat()) = 0....

They don't work. I get errors due to the subscript being out of range if the array isn't dimensioned to some size. In this case, so far, I simply position a detection statement at the start of the routine "If Ubound(Cat()) > 0", and if an error is generated because of the subscript problem, I determine that there must not be any elements in the array, and just exit either with or without an error message, depending on whether the user may be loading a form (which is where I check in one instance) in which some other function not requiring the array may be the desired goal. I then leave array related errors associated with functions called from the form to specific functions that MUST use the array.

Is there a better way to do this? There MAY be some element of a gamble in my use of the error generated by the "If Ubound(Cat()) > 0" statement for an array with no elements that I am simply missing, even if it is the only statement associated with the error message. It also makes it hard to use a "catch-all" error message for an entire routine, where I am entering a form and may want to enable access to some buttons that don't need the array information.

Thanks.

Check If Array Has 0 Elements
So I declare an array with an undefined amount of elements, such as "Dim Array() As Integer" with the intention of resizing it later. Is there a function I can use that will check to see if the array is still empty? Calling Ubound on it gives a Subscript Out Of Range error.

Removing Elements From A Array
Removing elements from a array as I scroll through a listing of files in a text list. As I find the file I wish to remove it from my array. Example 1.txt after finding the file I wish to remove it from my list. When I try Redim Preserve I get a “array is fixed or temp. locked”

How do I unlock to edit array or is there a better way to remove an element from my array ?

How To Compare Elements Of An Array
Hello!

Have a look at this

Dim Temp(1 to 5) as byte

Temp(1) = 1
Temp(2) = 2
Temp(3) = 2
Temp(4) = 3
Temp(5) = 4

As you can see, 2 of elemets above have same value.

I want to know how to detect if 2 elements have same value, and add them. In this case, the sum is 4.

Also, how to detect if there are 2 pairs, e.g:
Temp(1) = 1
Temp(2) = 1
Temp(3) = 2
Temp(4) = 2
Temp(5) = 5

Two pairs here is: Temp(1) = Temp(1) | Temp(3) = Temp(4)
The sum of both pairs = 2 + 4 = 6

Removing All Elements From An Array
hi there ...

Is there something special I need to do inorder to get this to work for me...

im running windows 2000 server ... and the array I'm attempting to verify that is empty or not is returned from the "Filter" method..

checkIfEmpty = Filter(stringArray, "somestring", True, vbTextCompare )

If (Not checkIfEmpty) = -1 Then

' this is not getting executed..

End If

Note : Filter apparently returns an empty array when "somestring" is not
found in 'stringArray'

thanks ..

deez

Checking If Array Has Elements
I have an array declared like this...

Dim a() as integer

It may or may not have been ReDim'ed to include elements. How can I check if it has elements or not? (Checking it with LBound throws an error.) I suppose I could just make a function to check it with LBound, and if it throws an error then return false, but I wondered if there's a better, more elegant way.

Counting Array Elements
is there an easy way to count the number of the element in an array? Im creating a flat array with the Split function and I want to know how substrings were entered into the array.

Can I Randomize Array Elements?
If I have this:

Code:
Dim myarray(0 to 4, 0 to 3)]

For x = 0 to Ubound(myarray)

'get array info
'pass array info to a sub

Next x

This array has 4 elements that I pass to a sub that changes parameters of a calculation. It passes 5 diff sets of data [myarray(0 to 4, 0 to 3)]. There are times when I want to pass myarray(2,0) before I pass myarray(0,0). Is there any way to randomize with array elements get passed?

Array Elements Combinatorics
Lets say we have an array with N elements. How we can have all the possible combinations between those elements?

Is it possible to store those combinations to a database?

e.g.

{1,2,5,6,9}

(1,2) (1,5) (1,6) (1,9) (2,5) (2,6) (2,9) (5,6) (5,9) (6,9)
(1,2,5) (1,2,6) (1,2,9) (1,5,6) (1,5,9) (1,6,9) (2,5,6) (2,5,9) (5,6,9)
(1,2,5,6) (1,2,5,9) (1,2,6,9) (1,5,6,9) (2,5,6,9)

How To Convert Elements Of An Array
hi.

I was just wondering if anyone can tell me how I would be able to convert string elements of an array into integer values. For example, I have an array that encompasses a range of numbers; however, these numbers are recognized as strings, so when i sort let say- 1,2,5,3,12 ... i get 1,12,3,5-

if anyone can help... that'd be great. Thanks

Easy Way To Add All The Elements Of An Array?
Right now I'm writing out each array address and adding them together as follows:

MyArray(0,0) + MyArray(1,0) + MyArray(2,0) + MyArray(3,0)...

I'm doing this for 59 elements, then dividing this value by 60 for an average.

I'm just wondering if there is some other code that you can direct the addition of all the elements of the array more easily?

Removing All Elements From An Array
I declared an array like:

Dim MyArray() as Integer

In a procedure I have:

Redim MyArray(1 to 5)

How do I remove the 5 elements in this array?

I tried:

Redim MyArray()

But that doesn't work. Is it possible?

Wilbert

How To Split The Array Elements
In array have a big message like ("God is Great") .I want to split the words and stored into the different variables . a=God, b=is and c=Great.
pls give me a solution

Help With Adding The Same Elements Of The Array
I am new to programming and I have hard time at work

code goes in DB find a valeu and compare with a hardoced value form a Array
if found repalce and count.
same for locating the province and change the tax with values from the array and count

For j = 0 To 19
If DsPost("EMP_EE_Share") = dOldRate(j) Then
dCount_EeShareRate(j) = dCount_EeShareRate(j) + 1
i = 1
NewValue = dNewRate(j)
If DsPost("Posts RESNum") = 7 Then
Tax1 = dOnt_tax(j)
dCount_OntEeShareTax(j) = dCount_OntEeShareTax(j) + 1
Else
If DsPost("Posts RESNum") = 9 Then
Tax1 = dQue_tax(j)
dCount_QueEeShareTax(j) = dCount_QueEeShareTax(j) + 1
End If
End If
End If
Next

printing

My code for printing is

For j = 0 To 19

strAudit = dCount_OEeShareTax(j) & " records o tax share updated to " & CStr(Format(dOnt_tax(j), "#0.00"))
Print #intLogFNum, strAudit & strCR
Next

29 records O tax share updated to 6.93

0 records O tax share updated to 6.93

0 records O tax share updated to 6.93

9 records On tax share updated to 6.93

0 records tax share updated to 6.93

what I want to compare if value of the elements from the array are 6.93 and add 29 +0+ 9 so total value will be 38 ....

Removing Array Elements
Hi

I have an array as follows:

ArrName(0)="Carl"
ArrName(1)="Sarah"
ArrName(2)="Fiona"
ArrName(3)="Paul"

Can you please let me know how I can remove ArrName(2) and decrease the arrName length by 1, for example. Would I have to do the following:

ArrName(2)=ArrName(3)
Remove ArrName(3)

Or is there an easier way

Dynamic Array Has Elements In It
I have a procedure that populates a dynamic array that is passed to it.
Before I call the procedure, I prepare the array with a Erase ArrayName statement.
Then I call the procedure, which will redim it to the approprate size and populate it.

Under certain circumstances however, the procedure has nothing to fill the array with, so it's left in the same state as was orginally passed (aka empty)

After the procedure runs, I check to see how many elements are present by using UBound, but this fails whenever the array is empty.

So my question is:
Does VB have something other then UBound and LBound for checking if a array has elements in it?

Thanks

Display Elements In Array
I started out with this code to read the attached file. What I want to be able to do is read the Name 1st then have the dates and numbers to follow looping thru each by the set of numbers they correspond to. All the names with 1's,2's,3's and so on. Plus I can't get it to print in anything big enough to view it.
Example:
sailwind
20050224 78 85
20050116 76 85

Sydsational
20050226 81 72
20050211 87 63
and so on for each name that is associated with #1, then go on to #2
How would this work ??

Dim strName() As String
Dim x As Integer

Open "C:Pace.TXT" For Input As #1

Do While Not EOF(1)
ReDim Preserve strName(x)
Input #1, strName(x)
x = x + 1
Loop

Close #1

Dim y As Variant

For Each y In strName
picture1.Print y
Next

Inserting Elements Into An Array
Hi all,

Complicated this one:
I have a richtextbox that I want the user to be able to select text with and then bold it. The app will then output the html.
ie:
VB Code:
rtb.text = "hello all at vb forums"

This text is inserted into a string array
VB Code:
myArray() = {"h","e","l","l","o", etc.....}

I then select the "all" word and click my bold button.
My program then determins the start of the selected text and redims the array then shifts each elements contents along by 3 so I can insert the "<B>" tag at the start of the selected text.
I then determine the end of the selected text and shift the rest of the elements contents up by 4 so I can insert the "</B>" tag.
the text in the rtb stays the same but a new string is created with the HTML formatting.
ie: hello <B>all</B> at vb forums

My problem is now what if the user selects another portion of the text to bold. I can't shift the array elements of the formatted array as I don't know where in the formatted string the start location is since i've added new elements.

I'm sure I've not explained that clearly but I hope someone get's the idea!