Getting Textbox data into an Array: VB 2008

G

GeekBoy

I did not see another group for this so I presume this is the correct one to
ask such a question.

Anyway, I need to get data entered into a textbox and put it all into an
array. I have looked and cannot find such an example of how to accomplish
this.

What I am trying to do it type in a set of numbers (e.g. 10 20 30....) and
fill in an array with those numbers.

Thanks for any gudiance.
 
J

Jack Jackson

I did not see another group for this so I presume this is the correct one to
ask such a question.

Anyway, I need to get data entered into a textbox and put it all into an
array. I have looked and cannot find such an example of how to accomplish
this.

What I am trying to do it type in a set of numbers (e.g. 10 20 30....) and
fill in an array with those numbers.

Thanks for any gudiance.

The String.Split method will break up a string.

Dim nums() as String = textbox1.Text.Split(" "c)
 
J

James Hahn

Do you mean that each line in the text box is going to be one element in the
array?

Dim s() = Split(TextBox1.Text, vbCrLf)

Or is it one line in the text box with mumbers separated by spaces?

Dim s() = Split(TextBox1.Text, " ")
 
G

GeekBoy

Jack Jackson said:
The String.Split method will break up a string.

Dim nums() as String = textbox1.Text.Split(" "c)


Thanks for the reply.

Here is what I got so far. I guess I need to do some more reading on this. I
really do not have the time at this moment.

Dim array = New Integer(0 To 15) {}
Dim j As Integer
Dim s() As String = Split(txtEnterArray.Text, " ")

For j = 1 To array.GetLength(0)
s(j) = array(j)

Next j

GB
 
J

James Hahn

Dim array(15) as integer
Dim j As Integer
Dim s() As String = Split(txtEnterArray.Text, " ")

For j = 0 To S.Length - 1
array(j) = ctype(val(s(j)), Integer)
Next j
 
C

Cor Ligthert[MVP]

GeekBoy,

Why do you make it yourself so difficult.
Jack gave you the complete answer, that is all you need.

You asked about numbers, as you mean values by instance integers, you can do
after that.

\\
dim x(nums.length - 1) as integer
For i = 0 to nums.length - 1
x(i) = CInt(nums(x))
next
///

You have to check f the numbers are real a values, however that is again
another question.

Be aware the above code can contains typos because I typed it direct in this
message

Cor
 
G

GeekBoy

Cor Ligthert said:
GeekBoy,

Why do you make it yourself so difficult.
Jack gave you the complete answer, that is all you need.

You asked about numbers, as you mean values by instance integers, you can
do after that.


Sorry, I do C++. This is actually easier in C++ than Visual "Basic" as no
conversion, flipping, manipulation, etc is needed. Just define the data
type and accept input.
\\
dim x(nums.length - 1) as integer
For i = 0 to nums.length - 1
x(i) = CInt(nums(x))
next


Thanks for your input also.
 
G

GeekBoy

James Hahn said:
Dim array(15) as integer
Dim j As Integer
Dim s() As String = Split(txtEnterArray.Text, " ")

For j = 0 To S.Length - 1
array(j) = ctype(val(s(j)), Integer)
Next j


Thanks a lot John for th eextra help.

GB
 
V

vbStudent

Dear All,

I want to sign textbox string data to array, each letter in one index.

i.e. if I write in the textbox vb.net .. I need to store store it in an
array as following
array(0)=v
array(1)=b
array(2)=.
array(3)=n
array(4)=e
array(5)=t

How can I do that .. please reply me soon.

Thanks for your cooperation
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top