Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Splitting the data is certainly possible, but it all depends on the actual format of the data. If the data is always formatted with a comma followed by a space between each value, then you can use the <code>String.Split</code> method, like this:</p> <pre><code>Dim data As String = "27, 34, 56, 94, 23" Dim values() As String = data.Split({", "}, StringSplitOptions.None) </code></pre> <p>The <code>String.Split</code> method returns an array of strings where each item in the array is one of the delimited values.</p> <p>As far as displaying them on a <code>Form</code>, if you want to display them in a column of <code>Label</code> controls, you would need to create a new <code>Label</code> for each item in the array. Either you would need to have them already on the form, from design-time, or you would need to dynamically instantiate the <code>Label</code> controls at run-time. Neither is an option that I would recommend, however. If you need to display a column of data, there are better controls to use for that sort of thing than a <code>Label</code>. </p> <p>I would recommend using a <code>ListBox</code> control to display them. The advantage of the <code>ListBox</code> control, besides convenience, is that it can display any number of items. If there are too many items to fit in the control, it will show a scroll bar so the user can scroll up and down through the items. Here's how you could fill a <code>ListBox</code> from the string array:</p> <pre><code>ListBox1.Items.AddRange(values) </code></pre> <p>Alternatively, if you really need to use a <code>Label</code> control, for some reason, you could display each item on a separate line in a single Label control. To do that, you'd need to join all of the items together using the <code>NewLine</code> string as the delimiter, for instance:</p> <pre><code>Label1.Text = String.Join(Environment.NewLine, values) </code></pre> <p>Raja provided an excellent example of how to loop through all the <code>TextBox</code> controls on the form and build an <code>ArrayList</code> containing all of their split values. I would caution you, however, that it will find <em>ALL</em> <code>TextBox</code> controls on the form, so if you have any other text boxes, you will need to alter the logic a little bit. My only real suggestion to improve upon what he did is, instead of using an <code>ArrayList</code>, you should be using a <code>List(Of String)</code>. The <code>ArrayList</code> is not type-specific, so it's less safe, and is therefore not recommended. It's an older class from the early days of .NET, back before generics were supported. Now-a-days, even if you need a type-unspecific list, most people recommend using <code>List(Of Object)</code> rather than <code>ArrayList</code>.</p> <p>To build a list of the strings from multiple text boxes, and then add them to a <code>ListBox</code>, you can do this:</p> <pre><code>Dim allValues As New List(Of String)() For Each i As TextBox In Me.Controls.OfType(Of TextBox)() allValues.AddRange(i.Text.Split({", "}, StringSplitOptions.None)) Next ListBox1.Items.AddRange(allValues.ToArray()) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload