digitaldrew
Well-known member
- Joined
- Nov 10, 2012
- Messages
- 167
- Programming Experience
- Beginner
I've got a richtextbox which will have different amounts of items in it. Sometime it may have 6, sometimes it may have 12..etc. I've taken all those items and put them into one array which we'll call Array1. What I want to do now is take 10 items from that array and put them into a separate array (Array2) which I will then take and pass within a web request.
The issue I'm having is that I always want Array2 to always have 10 items. If Array1 only has 5 then I want it to put those 5 in there twice. If it has 15 I want it to send the first request with the first 10 and the second request with the remaining 5 plus 5 from the first 10, and so on. It should constantly cycle through Array1 and pull the next 10 items, if it reaches the end then it goes and takes them from the beginning.
I've done some experimenting and if I use this code
I'm able to get the first 10 items, but that's it. If there are more than 10 items in the richtextbox those will never be touched.
I also tried this code
This will try and skip 10 right from the get go so if there are less than 10 items in the richtextbox it won't take anything.
If I try setting up a loop, for example:
This will take the first 10 no problem, but if there are only 12 items in the richtextbox then it only takes 2 during the second request and stops after that because it's hit the end of the array.
Is what I'm trying to do even possible? No matter what I can't figure out how to get one array to constantly grab 10 items from another and start at the beginning if necessary. Any help/input would be appreciated!
The issue I'm having is that I always want Array2 to always have 10 items. If Array1 only has 5 then I want it to put those 5 in there twice. If it has 15 I want it to send the first request with the first 10 and the second request with the remaining 5 plus 5 from the first 10, and so on. It should constantly cycle through Array1 and pull the next 10 items, if it reaches the end then it goes and takes them from the beginning.
I've done some experimenting and if I use this code
VB.NET:
Dim Array2 = Array1.Cast(Of String).Take(10).ToArray()
I also tried this code
VB.NET:
Dim Array2 = Array1.Cast(Of String).Skip(10).Take(10).ToArray()
If I try setting up a loop, for example:
VB.NET:
Dim i As Integer = 0
While Something > Something
Dim Array2 = Array1.Cast(Of String).Skip(i * 10).Take(10).ToArray()
'do some work here
i = i + 1
End While
Is what I'm trying to do even possible? No matter what I can't figure out how to get one array to constantly grab 10 items from another and start at the beginning if necessary. Any help/input would be appreciated!