Question Get text from multiline textbox

12padams

Well-known member
Joined
Feb 19, 2010
Messages
48
Programming Experience
Beginner
Ok basically I want to set some variables from lines on a text box.

The below code is what i want to do but unable to find a way to do it

VB.NET:
moveactionamount(1) = savebox.Text.line1
moveactionamount(2) = savebox.Text.line2
moveactionamount(3) = savebox.Text.line3
moveactionamount(4) = savebox.Text.line4

the textbox itself has random numbers between -10 and 10 on each line.

e.g.

1
-5
4
2
0
3
0
8
0
0
10

so what is the write code that I should use to do this...

I could also read it from a file... either way from textbox or file how do i read each line and set it as a value in the array?
 
The TextBox has a Lines property, which returns a String array. If your 'moveactionamount' is a String array then you can simply assign directly from the property to the variable and replace the existing array, if that's appropriate. Otherwise, you can get elements by index from the String array and assign them by index to the other array, converting if required. If there's a 1:1 correspondence then you can use a For loop.
 
Dim myArray As String()

myArray = Split(TextBox1.Text, vbCrLf)

For Each obj In myArray
MsgBox(obj)
Next



In the example above, it will show a msgbox for each position of the array. You can call specific positions in the array, starting from 0 to myArray.Count -1 (because it starts at 0, not 1). For instance:

MsgBox myArray(2)

will show the 3rd position in the array.
 
Dim myArray As String()

myArray = Split(TextBox1.Text, vbCrLf)

For Each obj In myArray
MsgBox(obj)
Next



In the example above, it will show a msgbox for each position of the array. You can call specific positions in the array, starting from 0 to myArray.Count -1 (because it starts at 0, not 1). For instance:

MsgBox myArray(2)

will show the 3rd position in the array.
You must have missed this:
The TextBox has a Lines property, which returns a String array.
VB.NET:
For Each line In TextBox1.Lines
 
Back
Top