?
Solved

VB.Net MultiLine Text Boxes

Posted on 2016-08-26
3
Medium Priority
?
88 Views
Last Modified: 2016-08-27
Here is my problem, i have a multi line Text Box and a List Box on my form.
The user can copy and paste a List of numbers in the multi line text Box.
When he clicks on Process i want to read line for line from text box and then
do some validation and if successful move the item to list box and remove from
text box.
I have my code who does the validation and putting int into the list box,, but having
issues with the removing from text box.

I tried to load the lines into a string list and then remove from string but problem
is that if i remove the item the list no longer has the same count as when i start and
the system will complain index out of range

Any ideas how to solve this cleanly ?
0
Comment
Question by:AlexPonnath
  • 2
3 Comments
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 41772398
Can you show your code and how you manipulate the lines in the TextBox? Are you using the Lines collection?
0
 

Author Comment

by:AlexPonnath
ID: 41772458
If txtNumbers.Lines.Count > 0 Then
            Dim newList As List(Of String) = txtNumbers.Lines.ToList
            For i As Int32 = 0 To newList.Count - 1

                lbNumbers.Items.Add(AddPhoneFormat(newList.Item(i)))
                ' Remove the first line.  
                'newList.RemoveAt(i)

            Next
        End If

Open in new window

0
 
LVL 64

Accepted Solution

by:
Fernando Soto earned 2000 total points
ID: 41772561
Hi Alex;

Try this modified version of your code. It should do what you need.
If txtNumbers.Lines.Count > 0 Then
    Dim newList As List(Of String) = txtNumbers.Lines.ToList
    '' Access the newList in reverse order so that deleted items do not effect un-processed items
    '' by having its index changed and therefor changing all other item index
    For i As Int32 = newList.Count - 1 To 0 Step -1
        '' Because items are being inserted in reverse order use the Insert methods in place of
        '' The Add method and always Insert at index zero.
        lbNumbers.Items.Insert(0, newList.Item(i))
        'Remove the first line.  
        newList.RemoveAt(i)
    Next
    '' Now seeming you are working with a copy of the Items in the TextBox you need to place the 
    '' Items that were not removed back in the TextBox
    txtNumbers.Lines = newList.ToArray
End If

Open in new window

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question