Text in a Text Box

What I would like to do is show data from a txt file in a text box.  But that's not all.  I would like to look at the previous line or the next line of the text file in the text box.  This txt file has multiple lines of text and my project has multiple text boxes, so I'm not only bringing in data to one text box.  Here is a sample of a text file:

12345   SMITH   JOE      B
12345   EVANS   BARBARA  C

So, I would like to show each of these fileds in a different txt box and be able to go from the BOF to the EOF by looking at the data in the text boxes.  Thanks in advance for the help.
hcougarAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MarineCommented:
i don't undersanad your questin really. But wouldn't it be better to load this data from text file to a flexgrid control ? i think it would be a better solution for you. Here is the code that would split the file and populate the msFelxGrid.


Dim str As String, sArray() As String, i
Open "C:\windows\desktop\val.txt" For Input As #2
msGrid.Rows = 1
i = 0
Do Until EOF(2)
    Input #2, str
    sArray = Split(str, "  ", -1, vbTextCompare)
    msGrid.AddItem sArray(0) & vbTab & sArray(1) & vbTab & sArray(2) & vbTab & sArray(3)
    i = i + 1
Loop
Close #2

'sarray=Split(str,"",-1,vbtextcompare)
note the second argument is a delemiter. You specify how the fields are separated. If the fields in a file sperated by a coma or an <!> or any other cherecter write it there. Best of luck
0
hcougarAuthor Commented:
Thanks for the input Marine, but that won't work for what I need.  I really need the text to be in text boxes.  All I want to do is put the first column in a text box, the second column in a different text box, etc., etc..  
0
RuchiCommented:
this text file looks like this...
 
12345 SMITH JOE B
12345 EVANS BARBARA C

this just gives you an idea. use split function for your problem. that way, you can extract a certain field using a certain element in the array.

Private Sub Command1_Click()
    Dim s1 As String
    Dim tmparray() As String
    Open "C:\test.txt" For Input As #1
    While Not EOF(1)
    Line Input #1, s1
    Wend
    tmparray = Split(s1, " ")
    Text1.Text = tmparray(0)
    Text2.Text = tmparray(1)
    Text3.Text = tmparray(2)
    Text4.Text = tmparray(3)
    Close #1
End Sub
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

MarineCommented:
I'll post you another answer but using grid is just better its still my opinion no more extra text boxes cause every column would match the column in your text file.
0
hcougarAuthor Commented:
Marine, I'll wait for your answer since you were the first to answer me.  Thanks.
0
hcougarAuthor Commented:
Ruchi, your code only picks up the first row.  I can't advance to the next row in the text file.
0
RuchiCommented:
it'd be more easier if you use database, not flat file, for "going from the BOF to the EOF"
0
hcougarAuthor Commented:
I'll tell you, I would use a database but the only problem is that my file has a header and a footer in the file.  
0
MarineCommented:
Ok this wll work
Dim str As String, sArray() As String, i
Open "C:\windows\desktop\val.txt" For Input As #2
i = 0
Do Until EOF(2)
    Input #2, str
    i = i + 1
    sArray = Split(str, "  ", -1, vbTextCompare)
    Text1.SelText = sArray(0) & vbCrLf
    Text2.Text = sArray(1) & vbCrLf
Loop
Close #2

Just make srue that both text boxes are set to multi line =true and scroll bars are also availabel
0
MarineCommented:
forgot to change the second textbox text2.seltext instead of .text property i tested it worked just fine.
0
MarineCommented:
another thin forget the counter i had it in my own example doing somthing.
0
hcougarAuthor Commented:
Marine, it's only printing out the first record.  It doesn't show the other records.
0
MarineCommented:
Hmm that can't be true. I tested it and it worked fine. You have to make sure that the TextBox multiLine property is set to True and that ScrollBars are set to either both or vertical. If you want i can email my sample. It worked just fine. Just make sure you set these properties.
0
hcougarAuthor Commented:
Yeah, I set the properties and it only brings in the first line.  My email is jellis8538@aol.com
0
MarineCommented:
I sended you an email my Email is Crutoy@aol.com if you wanna chat IM me.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
hcougarAuthor Commented:
It wasn't quite what I was wanting but I at least have something to work with.  Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.