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:

aaaaa_aaaaa_000.000.000.000_0000
bbbbb_bbbbb_111.111.111.111_1111
ccccc_ccccc_222.222.222.222_2222

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

000.000.000.000_aaaaa_aaaaa,0,000.000.000.000,0000,0,aaaaa,aaaaa,0,1,0,0
111.111.111.111_bbbbb_bbbbb,0,111.111.111.111,0000,0,aaaaa,aaaaa,0,1,0,0
222.222.222.222_ccccc_ccccc,0,222.222.222.222,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("_") 
mynumberlist.Add(StringSplit(1)) 
RichTextBox1.Text = StringSplit(2) & "_" & StringSplit(0) & "_" & StringSplit(1) & ",0," & StringSplit(2) & "," & StringSplit(3) & ",0," & StringSplit(0) & "," & StringSplit(1) & ",0,1,0,0"
        Next
Posted
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 =
by
RichTextBox1.AppendText


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