0

I am trying to get some code in Visual Basic to display on two lines. Here is my code below,

Dim v_names As String()

Dim v_nums As String()

Dim v_list As String
v_names = Me.PN_ComboBox.SelectedValue.Split(":")(3).Split(";")
v_nums = Me.PN_ComboBox.SelectedValue.Split(":")(4).Split(";")
v_list = ""

For i = 0 To (v_names.Length - 1)

     v_list = v_list & v_nums(i) & ":" & v_names(i)

Next i

Me.Vnumber_Label.Text = v_list

Currently it is displaying as:

123: bill:456: bob

I would like it to display as:

123: bill
456: bob

Any suggestions?

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794

2 Answers2

0

The constant "VbCrLf" can help you with that, I just searched on google :| And StackOverflow itself has topics about it answered

v_list = v_list & v_nums(i) & ":" & v_names(i) & VbCrLf

or

v_list = v_list & v_nums(i) & ":" & v_names(i) & Environment.NewLine
0
Dim fields = Me.PN_ComboBox.SelectedValue.Split(":")
Dim v_names As String() = fields(3).Split(";")
Dim v_nums As String() = fields(4).Split(";")
Dim strings = v_names.Zip(v_nums, Function(name, num) $"{name}:{num}")

Me.Vnumber_Label.Text = String.Join("<br/>", strings)

Here's a working test:

https://dotnetfiddle.net/7x7MQX


Oops! I missed the asp.net tag. In an ASP.Net context, a simple line break is not enough. Html doesn't care, and treats all white space the same. You need <br/>. I've updated the answer above to account for this.

Furthermore, putting <br/> into the label text might not be enough, because the label control can html-encode it. You need to set the label to not do that (and I'm drawing a blank where to do this at moment, but now that you know it needs to be done you can look up where as quickly as I).

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794