ArrayList looping
-
Hello Everybody My ArrayList (name aList) is Follows: aList(0) = 4, 5 aList(1) = 6, 7 aList(2) = 8, 9 What I want to call function as below:
Dim aa() As String
for i = 0 to aList.Count - 1
aa(i) = myFunction (aList(0,0), aList(0,1), aList(1,0), aList(1,1))
Next
Every Single time myFunction will take 4 values from aList For Example: i = 0 , will take value from aList(0) and aList(1) i = 1 , will take value from aList(0) and aList(2) i = 2 , will take value from aList(1) and aList(2) Please tell me some logic Thanks Sarfaraj
Sarfarj Ahmed
-
Hello Everybody My ArrayList (name aList) is Follows: aList(0) = 4, 5 aList(1) = 6, 7 aList(2) = 8, 9 What I want to call function as below:
Dim aa() As String
for i = 0 to aList.Count - 1
aa(i) = myFunction (aList(0,0), aList(0,1), aList(1,0), aList(1,1))
Next
Every Single time myFunction will take 4 values from aList For Example: i = 0 , will take value from aList(0) and aList(1) i = 1 , will take value from aList(0) and aList(2) i = 2 , will take value from aList(1) and aList(2) Please tell me some logic Thanks Sarfaraj
Sarfarj Ahmed
your example does not give a complete picture, or does it? Do you have only 3 items in your array or can it be more? ( I'm inclining to think more) what is the correlation between the example you have with an array of 10 items? will double loop work for your?
for i = 0 to aList.Count - 2
for j = i+1 to aList.Count - 1
aa(i) = myFunction aList(i), aList(j)this will produce something like this
aList(0) , aList(1)
aList(0) , aList(2)
aList(1) , aList(2)Yusuf
-
your example does not give a complete picture, or does it? Do you have only 3 items in your array or can it be more? ( I'm inclining to think more) what is the correlation between the example you have with an array of 10 items? will double loop work for your?
for i = 0 to aList.Count - 2
for j = i+1 to aList.Count - 1
aa(i) = myFunction aList(i), aList(j)this will produce something like this
aList(0) , aList(1)
aList(0) , aList(2)
aList(1) , aList(2)Yusuf
Dear Yusuf Thanks for your reply. There will be three items into aList. Like below: aList(0) will keep two values 7 and 8 aList(1) will keep two values 4 and 6 aList(2) will keep two values 5 and 9 I have to call a function which will take 4 values from aList (every single aList row keep 2 values) First Time I have to send value from aList(0) and aList(1) Second Time I have to send value from aList(0) and aList(2) Third Time I have to send value from aList(1) and aList(2) Thanks
Sarfarj Ahmed
-
your example does not give a complete picture, or does it? Do you have only 3 items in your array or can it be more? ( I'm inclining to think more) what is the correlation between the example you have with an array of 10 items? will double loop work for your?
for i = 0 to aList.Count - 2
for j = i+1 to aList.Count - 1
aa(i) = myFunction aList(i), aList(j)this will produce something like this
aList(0) , aList(1)
aList(0) , aList(2)
aList(1) , aList(2)Yusuf
more senario for i = 0 to aList.Count - 2 j= i + 1 to aList.Count - 1 aa(i) = myFunction (aList(0,0), aList(0,1), aList(1,0), aList(1,1) like this
Sarfarj Ahmed
-
Hello Everybody My ArrayList (name aList) is Follows: aList(0) = 4, 5 aList(1) = 6, 7 aList(2) = 8, 9 What I want to call function as below:
Dim aa() As String
for i = 0 to aList.Count - 1
aa(i) = myFunction (aList(0,0), aList(0,1), aList(1,0), aList(1,1))
Next
Every Single time myFunction will take 4 values from aList For Example: i = 0 , will take value from aList(0) and aList(1) i = 1 , will take value from aList(0) and aList(2) i = 2 , will take value from aList(1) and aList(2) Please tell me some logic Thanks Sarfaraj
Sarfarj Ahmed
Array list is nothing but collections of item, you can not store 2 value on same index.
-
Array list is nothing but collections of item, you can not store 2 value on same index.
Kunal Pawar wrote:
Array list is nothing but collections of item, you can not store 2 value on same index.
So, if it is a collection of item, can't you have an item composed of many things which is stored on single index. :^)
' Creates and initializes a new ArrayList.
Dim myAL As New ArrayList()
myAL.Add("1,2")
myAL.Add("3,4")
myAL.Add("5,6")I'm not saying this is the most efficient way of doing it, just showing you that you can store more than one item in an index, by creating collection.
Yusuf
-
more senario for i = 0 to aList.Count - 2 j= i + 1 to aList.Count - 1 aa(i) = myFunction (aList(0,0), aList(0,1), aList(1,0), aList(1,1) like this
Sarfarj Ahmed