Solved

CSV items to multiline textbox in VB.NET

Posted on 2009-05-14
7
840 Views
Last Modified: 2013-11-26
I am using Visual Studio 2008. I am trying to take a line of comma separated items and send them to a multiline textbox.  For example "1,2,3,4" would appear in the textbox as:

1
2
3
4

I would like to do this in a For Each or For Next statement.
0
Comment
Question by:schwientekd
  • 3
  • 2
  • 2
7 Comments
 
LVL 15

Expert Comment

by:Walter Ritzel
Comment Utility
If you dont have the comma as a valid char for each value, you can try something like this:

Dim formatedValue as String

formatedValue = SourceCSVLine.Replace(",",CHR(13))

textBox.Text = formatedValue

Sorry for bad VB syntax... I'm C# guy....
0
 
LVL 8

Expert Comment

by:RyanAndres
Comment Utility
The following code assigns each delimited part as a new line
string line = "1,2,3,4";

textBox.Text = line.Replace(',', '\n');

Open in new window

0
 
LVL 8

Expert Comment

by:RyanAndres
Comment Utility
Someone beat me and I forgot to convert to VB:
Dim line As String = "1,2,3,4"

textBox.Text = line.Replace(","c, ControlChars.Lf)

Open in new window

0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:schwientekd
Comment Utility
I modified your lines slightly by replacing CHR(13) with vbCrLf and that did accomplish the simple question I asked.  However I was looking for a way to do this with a For statement.  The reason is that the thing I am trying to accomplish is much more complex but I was trying to start small.  The comma separated items I am using are actually going to be codes that are stored in a table.  Each code will have another column with a description and the descriptions are what need to appear in my textbox. Sorry for the long explanation which I don't expect to be answered in this post but I just wanted to explain my reason for wanting to use a For statement.
0
 
LVL 8

Accepted Solution

by:
RyanAndres earned 500 total points
Comment Utility
This code allows you to manipulate each line. If this is not what you're looking for please provide a sample input and expected output.


Dim str As String = "1,2,3,4"

Dim lines As String() = str.Split(","c)
 

Dim output As New StringBuilder()

For Each line As String In lines

    output.AppendLine(line.Trim())

Next

txtFirstName.Text = output.ToString()

Open in new window

0
 
LVL 15

Expert Comment

by:Walter Ritzel
Comment Utility
In this case, I think the last code from RyanAndres is what you are looking for.
0
 

Author Closing Comment

by:schwientekd
Comment Utility
I think that this will get me started.  Thanks.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…

763 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

14 Experts available now in Live!

Get 1:1 Help Now