We help IT Professionals succeed at work.

VB Create an array from textbox with comma separated values

Hi

I have a textbox with coma separate values in e.g. 123,432,234

I need to put these in to an array and loop though them.

How can I do this?

Thanks

Brasso

Comment
Watch Question

Dim numbers As String() = textbox1.Split(New Char() {","c})

Hope this help

Author

Commented:
Hi

How would I loop through the results of that though?

Thanks

Brasso
    For Each intValue In numbers
         textbox2.text = intValue.ToString()
     Next

Author

Commented:
I get 'split' is not a member of 'systems.web.ui.webcontrols.textbox'

humm, Are you working on Web

JavaScript strings have a split method that will return an array of elements.

myArray = textbox.value.split(",")



Also you can do

Dim numbers As String() = textbox1.text.Split(New Char() {","})
Paul MacDonaldDirector, Information Systems

Commented:
Change [Masteraco]'s sample to this:
  Dim numbers As String() = Split(TextBox1.Text, ",")

Commented:
You could do it like below:

Sub ParseString()
Dim MyStringValues As String
Dim TextBoxValues As String
TextBoxValues = Split(TextBox1.Text, ",")

MyStringValues = ""
For Each x_value In TextBoxValues()
  MyStringValues = MyStringValues  & TextBoxValues( x_values) & VBCrlf
Next

MsgBox (MyStringValues) 'Display values
End Sub
I post this correct answer:

Dim numbers As String() = textbox1.Split(New Char() {","c})

Hope this help