Reading in from a text box one line at a time programatically

G

Gary

hi,

say i have a textbox which is 7 lines in length

how do i read line one of that text box to a variable called lineone$
how do i read line two of that text box to a variable called linetwo$
...

etc.. for the seven lines in the text box.

the reason for this is I have a text box which has an address, and I
want to read one line at a time and split the address into different
address line fields, e.g. address1, address2 etc...


so i want a button that reads in the value of a text box on a form, and
assigns each line of that text box, to a seperate variable - so that i
can use each line on it's own later in the code.

thanks

gary.
 
D

Douglas J Steele

If it's displaying properly, your text must have a linefeed and a carriage
return character at the end of each line.

You should be able to split the lines into an array using the Split
function:

Dim varText As Variant

varText = Split(MyTextBox, vbCrLf)

Now, the first line will be varText(0), the second line will be varText(1)
and so on to the 7th line being varText(6).
 
G

Gary

Thankyou that is exactly what I wanted and it works a treat.

Now it has led me to a second question. and third.

Q1.
how do i check to see if vartext(1) starts with the string "company
number:"

if it does i will need to take the number out of the company number
string, in other words: -

Q2.
how do i strip out the number from a string in the following format:
"Company No. 05200000"
I want to put the number, in this case 05200000 into a variable on its
own.

thankyou

gary
 
F

fredg

Thankyou that is exactly what I wanted and it works a treat.

Now it has led me to a second question. and third.

Q1.
how do i check to see if vartext(1) starts with the string "company
number:"

if it does i will need to take the number out of the company number
string, in other words: -

Q2.
how do i strip out the number from a string in the following format:
"Company No. 05200000"
I want to put the number, in this case 05200000 into a variable on its
own.

thankyou

gary
"Company No. " is 12 characters, so you want everything from the 13th
character on.

NewString = Mid(OldString,13)
 

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