Click here to Skip to main content
15,559,455 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a listbox with the following lines with 3 unique strings in it:


(the output below is exactly what I need, For each line from Listbox to Richtextbox.text each on a new line):,0,,0000,0,aaaaa,aaaaa,0,1,0,0,0,,0000,0,aaaaa,aaaaa,0,1,0,0,0,,0000,0,aaaaa,aaaaa,0,1,0,0

Can someone help me with this in VB?
Sofar the code I am using is working but only for one line and I need it to do it with all lines from my Listbox.

Thank you

What I have tried:

Dim mynumberlist As New List(Of String)
For Each line As String In ListBox1.Items
Dim StringSplit() As String = line.Split("_") 
RichTextBox1.Text = StringSplit(2) & "_" & StringSplit(0) & "_" & StringSplit(1) & ",0," & StringSplit(2) & "," & StringSplit(3) & ",0," & StringSplit(0) & "," & StringSplit(1) & ",0,1,0,0"
Updated 5-Jun-22 3:07am

If you have code that words for one line, move it into a method that you pass a string, and which returns a string.
Then call it for each line in your listbox - you know how to do that, I'm sure.
Store the returned strings in a collection - a List or an Array is fine - then sort them into the order you need. (Array.Sort or Linq OrderBy will do it).
Then just set the RichTextBox.Lines property to the array of lines containing your sorted data.
Share this answer
After some brainstorming I found my solution was rather simple..

I replaced
RichTextBox1.Text =

and everything I wanted is working 100% now, I can change the order of strings however I want it to be.

Maybe not the most perfect code but for now it works like a charm..

If the experts have a better/cleaner code let me know :),
Hopefully this code is usefull to someone.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900