|
-
Jun 25th, 2007, 07:19 AM
#1
Thread Starter
Addicted Member
[RESOLVED] how to find the length of array in v.b 6.0
hi everybody,
in my application, i have to find the length of an array, is there any method to find the lenght of an arrray?(it should say how many elements are presented in that array).
i tried with "UBOUND" method but it gives the original sizeof the the array, but not the how many elements that r presented in that array....
If u know kindly help me. i stucked in my project for this only..
Thanks in advance,
Regards:
raghunadhs
-
Jun 25th, 2007, 07:39 AM
#2
Re: how to find the length of array in v.b 6.0
UBound is what you need:
Code:
Private Sub Command1_Click()
Dim arItems() As String
Dim arItems2(3, 5) As Integer
ReDim arItems(3) '4items
'for one dimentional array simply use Ubound
Debug.Print "arItems contains " & UBound(arItems) + 1
'for multidimentional array specify dimention
Debug.Print "arItems2 contains - 1st dimention: " & UBound(arItems2, 1) + 1
Debug.Print "arItems2 contains - 2nd dimention: " & UBound(arItems2, 2) + 1
End Sub
-
Jun 25th, 2007, 07:49 AM
#3
Re: how to find the length of array in v.b 6.0
Rhino Bull
Code:
Private Sub Command1_Click()
Dim test(10) As String
test(0) = "john"
test(1) = "michel"
MsgBox UBound(test)
End Sub
Now the messge says 10 while only two elements are filled. how i do count only the filled eliments? this is what ragunath expecting i think.
Last edited by Fazi; Jun 25th, 2007 at 07:53 AM.
-
Jun 25th, 2007, 08:04 AM
#4
Re: how to find the length of array in v.b 6.0
To find only "populated" items you'd have to loop through array - there is no any other way.
-
Jun 25th, 2007, 08:04 AM
#5
Re: how to find the length of array in v.b 6.0
ragunatan,
i think you will have to loop through your array uing lboud() to uboud() and count how many elemets value are <> "". Record each one which is <> ""
-
Jun 25th, 2007, 08:05 AM
#6
Re: how to find the length of array in v.b 6.0
-
Jun 25th, 2007, 08:07 AM
#7
Re: how to find the length of array in v.b 6.0
Or, depending on the way you fill your array, you could ReDim it everytime you add an item.
You could add 1 to the UBound of the array each time before you add another element.
Then, using UBound you do get the correct number.
-
Jun 25th, 2007, 08:07 AM
#8
Re: how to find the length of array in v.b 6.0
Validating agains empty string (or zero for numeric types) might not give correct results - either value could be valid so you'd have initialize array by populating each item with some default value.
This could very costly (memory and performance)...
BETTER approach is to use DYNAMIC ARRAY
where items are added when you need to add one.
-
Jun 25th, 2007, 08:17 AM
#9
Re: how to find the length of array in v.b 6.0
Yes, or a collection/dictionary which manages the resizing internally, which is a bit more efficient than manually resizing it every time you need to add an element.
-
Jun 25th, 2007, 10:53 PM
#10
Thread Starter
Addicted Member
Re: how to find the length of array in v.b 6.0
Thanks all,
i have solved it with your suggestions.....
regards:
raghunadhs
-
Apr 16th, 2010, 04:31 AM
#11
New Member
Re: [RESOLVED] how to find the length of array in v.b 6.0
-
Dec 10th, 2015, 05:43 AM
#12
Registered User
Re: [RESOLVED] how to find the length of array in v.b 6.0
Can any one help me to save data in JSON format
-
Dec 10th, 2015, 08:38 AM
#13
Re: [RESOLVED] how to find the length of array in v.b 6.0
You should start your own thread instead of piggy-backing on another that isn't even related to your question. The codebank has a JSON project that I'm sure describes how to read/write data
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|