Solved

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

Posted on 2014-11-13
3
256 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
  • 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 32

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 32

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
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…

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now