Write to a list box

A

alvin Kuiper

Hi i try this:
Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.OpenTextFile("h:\\mine databaser\tekst.txt")
Liste7.RowSource = ""
Do While Not a.readline = ""
Liste7.AddItem a.readline
Loop

In Tekst.txt i have 3 lines, i get number 2 lines and a error in :
Liste7.AddItem a.readline
Error: Input past end of file

And if i use:
Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.OpenTextFile("h:\\mine databaser\tekst.txt")
Liste7.RowSource = ""
Do
Liste7.AddItem a.readline
Loop While Not a.readline = ""
a.Close
I get number 1 and number 3 lines in my tekst file
and again the same error

So what do i do wrong
 
A

Alex Dybenko

hi,
try this:
Dim TextLine
Open "h:\\mine databaser\tekst.txt" For Input As #1 ' Open file.
Do While Not EOF(1) ' Loop until end of file.
Line Input #1, TextLine ' Read line into variable.
Liste7.AddItem TextLine
Loop
Close #1 ' Close file.


--
Best regards,
___________
Alex Dybenko (MVP)
http://accessblog.net
http://www.PointLtd.com
 
A

alvin Kuiper

Thanks Alex
If you have tiem maybe you can explain it to me?
I don't understand #1

Best regards
alvin


"Alex Dybenko" skrev:
 
D

Douglas J. Steele

#1 is what's referred to as a file number. In actual fact, Alex should have
suggested

Dim intFile As Integer
Dim strTextLine As String

intFile = FreeFile()
Open "h:\\mine databaser\tekst.txt" For Input As #intFile ' Open file.
Do While Not EOF(intFile) ' Loop until end of file.
Line Input #intFile, strTextLine ' Read line into variable.
Liste7.AddItem strTextLine
Loop
Close #intFile ' Close file.

just in case some other process was already using file handle 1.
 
D

Douglas J. Steele

I figured as much, and we know how good the code samples are in the Help
file! <g>
 

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