I want to set up an array and have 100+ items in the array anyone know how to split the line

Dim row() As Integer = {1, 2, 3, 4, 5, 6}

like this

Dim row() As Integer = {1, 
                        2, 
                        3, 
                        4, 
                        5, 
                        6}

Dani AI

Generated

asked how to break a long VB.NET array literal across lines. The suggestions from (mass edit/regex), (build at runtime) and (use Split) are all workable. The main things to clarify are (1) which VB version you’re using and (2) whether you want the values as a literal in source or loaded/generated at runtime.

If the goal is a readable literal in source:

  • In older VB you must use the explicit line-continuation character (_) at the end of each continued line.
  • In VB 2010+ the compiler allows implicit continuation inside groupings, so you can place each element on its own line without the underscore.

Examples (do not copy the originals from the thread):

' explicit continuation (pre-VB2010)
Dim nums As Integer() = { _
    10, _
    20, _
    30 _
}
' implicit continuation (VB2010+)
Dim nums As Integer() = {
    10,
    20,
    30
}

If maintaining a literal of 100+ items is painful, store the data externally or build it at runtime. A single CSV/text resource or file can be parsed into integers with String.Split and Integer.Parse (or LINQ), which keeps source code small and makes updates easier. That also fits ’s quick-edit idea but produces code that reads the data at runtime.

Troubleshooting tips:

  • If you see "Line continuation character is required" you’re using a VB version that needs _.
  • If parsing at runtime, trim entries and handle parse exceptions (Integer.TryParse) for robustness.

Microsoft docs on VB line-continuation rules are a good reference: .

Recommended Answers

All 3 Replies

If I had to it I would load the code into a text editor (like TextPad) that supports regular expressions and change "," to ",\n". If you don't have one then copy the following code into a file named (as an example) change.vbs.

text = "Dim row() As Integer = {1, 2, 3, 4, 5, 6}"
wscript.echo Replace(text,",","," & vbcrlf)

Replace the string in line 1 with your actual string, then run from the command line by

cscript change.vbs

Copy and paste the output into your code winidow.

use loop to insert your data in array , and then print then in textbox and manually use vbCrLf after printing each value , your data will be in your required format .

Regards

You could also use:

string.Split(New Char(","c)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.