digitaldrew
Well-known member
- Joined
- Nov 10, 2012
- Messages
- 167
- Programming Experience
- Beginner
I've been struggling to figure out how to do this and hope someone can help. Here is my scenario...
I have a RichTextBox with multiple items inside and the number of items may vary from one day to the next. I also have the option to run my program on either 1, 2 or 3 different threads (each thread will have its own array to work from). Once started, I would like the program to look at how many items are listed in the RichTextBox and then split them up evenly into each individual array.
For example, if I put 1 item in the RichTextBox and select 1 thread, it will simply add that one item into the array created for the first thread. If I put 3 items into the RichTextBox and select 3 threads, it will take the first item and add it to the first array, the second item and add it to the second array, and then add the third item to the third array. If I put 6 items in and select 3 threads, it will put the first two into the first array, the second two into the second array, and the final two into the third array. Keep in mind, there might be days where I have 5 items in the RichTextBox and 2 threads selected. If this were the case then I would want the first 2 items added to the first array and the remaining 3 added to the second array.
Here is some code I've been messing around with, but I know I'm way off because I've never done this before. You can tell by the very first line that if I don't have a round number it's not going to work. For example, if I were to put 7 items into the RichTextBox and select 3 threads, the Integer I'm going to get is 2.3333333
I have a RichTextBox with multiple items inside and the number of items may vary from one day to the next. I also have the option to run my program on either 1, 2 or 3 different threads (each thread will have its own array to work from). Once started, I would like the program to look at how many items are listed in the RichTextBox and then split them up evenly into each individual array.
For example, if I put 1 item in the RichTextBox and select 1 thread, it will simply add that one item into the array created for the first thread. If I put 3 items into the RichTextBox and select 3 threads, it will take the first item and add it to the first array, the second item and add it to the second array, and then add the third item to the third array. If I put 6 items in and select 3 threads, it will put the first two into the first array, the second two into the second array, and the final two into the third array. Keep in mind, there might be days where I have 5 items in the RichTextBox and 2 threads selected. If this were the case then I would want the first 2 items added to the first array and the remaining 3 added to the second array.
Here is some code I've been messing around with, but I know I'm way off because I've never done this before. You can tell by the very first line that if I don't have a round number it's not going to work. For example, if I were to put 7 items into the RichTextBox and select 3 threads, the Integer I'm going to get is 2.3333333
VB.NET:
'Get number of items in RichTextBox and divide by number of threads selected to determine how many items should go into each individual array
Dim itemsPerThread As Integer = txtItems.Lines.Count / nmThreads.Value
'Run loop to add the itemsPerThread into arrays
Dim myitemArray1 As New ArrayList
Dim myitemArray2 As New ArrayList
Dim myitemArray3 As New ArrayList
Dim x As Integer = 1
Dim arrayCount As Integer = 1
For i As Integer = 0 To txtItems.Lines.Count - 1
While x <= itemsPerThread
myitemArray(arrayCount).Add(i)
x = x + 1
End While
x = 0
arrayCount = arrayCount + 1
Next