Question Get user input into array

jojo159

New member
Joined
May 17, 2011
Messages
2
Programming Experience
Beginner
In my program, I need to have the user input a list of numbers separated by commas. How would I go about storing those numbers? Would I put them into an array? If so, how?
I'm REALLY new at this and I have been all over Google but I can't seem to get it. Please Help!
 

Joshdbr

Well-known member
Joined
Apr 7, 2011
Messages
211
Location
Montana, USA
Programming Experience
5-10
If I understand you right, you need to use the String.Split() method:

Dim strInfo As String = "Item1,Item2,Item3,Item3"
Dim strInfoArray() As String = strInfo.Split(",")

'Another option is to just create an array without using the Split() method:

Dim strInfoArray() As String = {"Item1", "Item2", "Item3", "Item4"}


You might also look into using lists, that way you can use the Add() function:

Dim lstInfo As New List

'Adding items
lstInfo.Add("Item1")

'Converting list to a string array
Dim strInfoArray() As String = lstInfo.ToArray()


Hope this helps
-Josh
 

Joshdbr

Well-known member
Joined
Apr 7, 2011
Messages
211
Location
Montana, USA
Programming Experience
5-10
Glad to help!
 

BlackByte

Well-known member
Joined
Jun 29, 2008
Messages
126
Location
South Africa, Durban
Programming Experience
1-3
Its always recommended to use the generic version of a list.

VB.NET:
Dim numbers As New List(Of Integer)
this prevents unboxing.
 

Joshdbr

Well-known member
Joined
Apr 7, 2011
Messages
211
Location
Montana, USA
Programming Experience
5-10
Right, sorry about that. I was just typing from memory :).

Dim lstInfo As New List(Of String)
 
Top Bottom