Solved

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

Posted on 2014-11-13
3
262 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 500 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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

734 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