Forums
New posts
Search forums
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
C# Community
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
VB.NET
VB.NET General Discussion
Adding Items From 1 RichTextBox into Different Arrays
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="digitaldrew, post: 186201, member: 41941"] 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 [CODE] '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 [/CODE] [/QUOTE]
Insert quotes…
Verification
Post reply
VB.NET
VB.NET General Discussion
Adding Items From 1 RichTextBox into Different Arrays
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.
Accept
Learn more…
Top
Bottom