Reading from txt file working but how to configurre the text file for word - please

G

gravesen

HI with some help from the lidt I got following code and it is no
almost working now. There two small things I would like to do :)

This is the code that reads the text file and sends it to m
textboxes:
-------------------------------------------------
Private Sub UserForm_Activate()
Dim iLin As Integer ' a counter for lines
Dim sTxt As String ' the text from a line
Open "c:\test\address.txt" For Input As #1
For iLin = 1 To 2 ' in case there are 5 lines
Input #1, sTxt ' get the text from the line
' MsgBox sTxt ' for testing
Input #1, sTxt
TextBox1.Text = sTxt
Input #1, sTxt
TextBox2.Text = sTxt
Input #1, sTxt
TextBox3.Text = sTxt
Input #1, sTxt
TextBox4.Text = sTxt
Input #1, sTxt
TextBox5.Text = sTxt
Next
' or

'Input #1, sTxt
'TextBox2.Text = sTxt
'...
Close #1
End Sub
---------------------------------

The first thing is that when I read from the text file it is like th
program doen't take the first line of text but if I leave a blank spac
I get errors.
I have this as test in my txt file.
--------------------------
1,1a, 1a, 1c, 1d, 1e, 1f
Lars Gravesen
Next line of text
3 line
4 line
5 line
6 line

---------------------------------------

The first line is not inserted in any textbox but if I delete it I ge
errors.

Also I would like to insert multiple line i a textbox but how can
tell this to the textbox in my txt file??

Any help would be so nice :)

Thanks

Lars Gravese
 
P

Perry

Textfiles usually have Chr(13) as designated end-of-line sign (EOL).
Below snippet uses this; if in yr case another EOL sign applies, you'll have
to adjust the code.

Dim sText As String, arrText, i As Integer
i = FreeFile
Open "c:\temp\lines.txt" For Input As #i
'read contents in one go
sText = Input(LOF(i), i)
Close #i
'split to array, EOL sign usually: Chr(13)
arrText = Split(sText, Chr(13))

'check first line of textfile
MsgBox arrText(0)

You can set the multiline state of a textbox by using
below example, and test it by using the sText variable
of above example ...

'assign multiline to textbox1
Me.TextBox1.MultiLine = True
Me.TextBox1 = sText

Krgrds,
Perry
 

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