Solved

VB.Net MultiLine Text Boxes

Posted on 2016-08-26
3
67 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 63

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 63

Accepted Solution

by:
Fernando Soto earned 500 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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

Suggested Solutions

Title # Comments Views Activity
Modal Popup Extender control 1 39
Help with consolidating excel files using VB.net 2 29
Iteration Help (Asp.net VB) 5 25
Access/Visual Basic Question 3 29
This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

820 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