Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Building a custom string based on data read from MultiLine Text Box

Posted on 2014-11-13
3
Medium Priority
?
268 Views
Last Modified: 2016-02-18
I was wondering what the best way is to do the following. I have a multiline textbox which I place text inand
then via function read line by like. The data in text box looks like this
NC
NCI
TLV
TTT
QACI

now what I like to do is read each line by line which I do via

For i = 0 To Val(TextBox1.Lines.Count) - 1
next

Open in new window


Which works all fine but now comes the part I am unsure off, I need to create an output in a second textbox which has a syntax like this

NC - NCI
NCI - TLV
TLV - TTT
TTT - QACI
QACI - END (End because its the last item in List and no more values)

So its the first item - 2nd Item, then 2nd Item - 3rd Item and so on as far as the logic goes
0
Comment
Question by:AlexPonnath
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 22

Expert Comment

by:plusone3055
ID: 40441236
For i = 0 To Val(TextBox1.Lines.Count) - 1
  if  val = "NC" Then 
 val = "NC - NCI" 
ELSE IF  val = NCI THEN 
val =  NCI - TLV
ELSE IF  (you get the idea :) ) 
next

Open in new window

0
 
LVL 34

Accepted Solution

by:
it_saige earned 2000 total points
ID: 40441260
Here is one way:
Public Class Form1
	Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		For i = 0 To Val(TextBox1.Lines.Count) - 1
			If i <> TextBox1.Lines.Count - 1 Then
				TextBox2.AppendText(String.Format("{0} - {1}{2}", TextBox1.Lines(i), TextBox1.Lines(i + 1), Environment.NewLine))
			Else
				TextBox2.AppendText(String.Format("{0} - END", TextBox1.Lines(i)))
			End If
		Next
	End Sub
End Class

Open in new window


Produces the following output:Capture.JPG
-saige-
0
 
LVL 34

Expert Comment

by:it_saige
ID: 40441436
And just to show another method, this one uses LINQ:
Public Class Form1
	Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		For Each value In (From item In TextBox1.Lines _
			  Select String.Format("{0} - {1}", item, _
				  (If(Array.IndexOf(TextBox1.Lines, item) <> (TextBox1.Lines.Count() - 1), _
					 String.Format("{0}{1}", TextBox1.Lines(Array.IndexOf(TextBox1.Lines, item) + 1), Environment.NewLine), _
					 "END"))))
			TextBox2.AppendText(value)
		Next
	End Sub
End Class

Open in new window


Produces the following results:Capture.JPG
-saige-
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

670 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