ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   about ARRAY variable (https://www.excelbanter.com/excel-programming/309787-about-array-variable.html)

Marek

about ARRAY variable
 
people, maybe my question sounds very stupid, but i try to ask you

i have array variable

for exampl.

dim ddd(2)
ddd(0)="aaa"
ddd(1)="bbb"
ddd(2)="ccc"


for each cc in ddd

msgbox cc.index

PEOPLE !, is there any property on array using which i can ge
current index of array ?????????????????


I dont want to use For statement.....

i simply want to know how to get INDEX of array


next



thank

--
Message posted from http://www.ExcelForum.com


Bernie Deitrick

about ARRAY variable
 
Marek,

You can either keep track of the index:

Sub TryNow2()
Dim ddd(0 To 2) As String
Dim cc As Variant
Dim myCount As Integer

ddd(0) = "aaa"
ddd(1) = "bbb"
ddd(2) = "ccc"

myCount = LBound(ddd) - 1

For Each cc In ddd
myCount = myCount + 1
MsgBox "Element " & myCount & " is " & cc & "."
Next cc

End Sub

OR, simply use the index when stepping through:

Sub TryNow()
Dim i As Integer
Dim ddd(0 To 2)

ddd(0) = "aaa"
ddd(1) = "bbb"
ddd(2) = "ccc"

For i = LBound(ddd) To UBound(ddd)
MsgBox "Element " & i & " is " & ddd(i) & "."
Next i
End Sub

HTH,
Bernie
MS Excel MVP


"Marek " wrote in message
...
people, maybe my question sounds very stupid, but i try to ask you

i have array variable

for exampl.

dim ddd(2)
ddd(0)="aaa"
ddd(1)="bbb"
ddd(2)="ccc"


for each cc in ddd

msgbox cc.index

PEOPLE !, is there any property on array using which i can get
current index of array ?????????????????


I dont want to use For statement.....

i simply want to know how to get INDEX of array


next



thanks


---
Message posted from http://www.ExcelForum.com/




Myrna Larson

about ARRAY variable
 
Hi, Bernie:

If the index is needed, I would certainly use that index as the variable in
the For/Next loop. My problem with 'For Each' is that I'm not completely
confident as to the order in which the members of the collection are
processed. Does it always start at the bottom and move up, or from the top
moving down? I haven't seen any documentation on this point, have you?



On Mon, 13 Sep 2004 12:33:11 -0400, "Bernie Deitrick" <deitbe @ consumer dot
org wrote:

Marek,

You can either keep track of the index:

Sub TryNow2()
Dim ddd(0 To 2) As String
Dim cc As Variant
Dim myCount As Integer

ddd(0) = "aaa"
ddd(1) = "bbb"
ddd(2) = "ccc"

myCount = LBound(ddd) - 1

For Each cc In ddd
myCount = myCount + 1
MsgBox "Element " & myCount & " is " & cc & "."
Next cc

End Sub

OR, simply use the index when stepping through:

Sub TryNow()
Dim i As Integer
Dim ddd(0 To 2)

ddd(0) = "aaa"
ddd(1) = "bbb"
ddd(2) = "ccc"

For i = LBound(ddd) To UBound(ddd)
MsgBox "Element " & i & " is " & ddd(i) & "."
Next i
End Sub

HTH,
Bernie
MS Excel MVP


"Marek " wrote in message
...
people, maybe my question sounds very stupid, but i try to ask you

i have array variable

for exampl.

dim ddd(2)
ddd(0)="aaa"
ddd(1)="bbb"
ddd(2)="ccc"


for each cc in ddd

msgbox cc.index

PEOPLE !, is there any property on array using which i can get
current index of array ?????????????????


I dont want to use For statement.....

i simply want to know how to get INDEX of array


next



thanks


---
Message posted from http://www.ExcelForum.com/




Bernie Deitrick

about ARRAY variable
 
Myrna,

I have never seen any documentation as to how Excel moves through arrays
when 'For Eaching' them, but in my experience, it always starts at the lower
bound and progresses up - the two subs that I posted return them in the same
order. Seems to work that way with cells, worksheets, workbooks, etc.

Of course, under closer questioning, I would admit "If Myrna doesn't know
for sure, then I certainly don't!" ;-)

Bernie

"Myrna Larson" wrote in message
...
Hi, Bernie:

If the index is needed, I would certainly use that index as the variable

in
the For/Next loop. My problem with 'For Each' is that I'm not completely
confident as to the order in which the members of the collection are
processed. Does it always start at the bottom and move up, or from the top
moving down? I haven't seen any documentation on this point, have you?





All times are GMT +1. The time now is 01:23 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com