How to read file contents into list box. 
Author Message
 How to read file contents into list box.

Greetings:

        I need to read the contents of a text file into a list box.
The file contains names, one per line.
        I have a text box that a user enters a new name into and this in turn
will add the name to the list in the list box via a command button.
        I can easily load the file contents into a text box, but then I
am unable to allow additional names to be entered.  On the other hand,
if I use a list box, I can update names into the box but the file
contents will not load into the list box, it is initially blank.
        Perhaps I am unaware of the proper coding to allow both of these
to work together.  I would very much appreciate any help that can be
offered.  Thanks,          Sean.



Sun, 04 Apr 1999 03:00:00 GMT  
 How to read file contents into list box.


writes

Quote:
>       I need to read the contents of a text file into a list box.
>The file contains names, one per line.
>       I have a text box that a user enters a new name into and this in turn
>will add the name to the list in the list box via a command button.
>       I can easily load the file contents into a text box, but then I
>am unable to allow additional names to be entered.  On the other hand,
>if I use a list box, I can update names into the box but the file
>contents will not load into the list box, it is initially blank.

open"textfile" for input as #1
do until eof(1)
  line input #1,a$
  listbox1.additem a$
loop
close #1

--
Peter Hesketh




Sun, 04 Apr 1999 03:00:00 GMT  
 How to read file contents into list box.

Quote:
>    I need to read the contents of a text file into a list box.
>The file contains names, one per line.
>    I have a text box that a user enters a new name into and this in turn
>will add the name to the list in the list box via a command button.
>    I can easily load the file contents into a text box, but then I
>am unable to allow additional names to be entered.  On the other hand,
>if I use a list box, I can update names into the box but the file
>contents will not load into the list box, it is initially blank.
>    Perhaps I am unaware of the proper coding to allow both of these
>to work together.  I would very much appreciate any help that can be
>offered.  Thanks,          Sean.

If I'm Understanding you correctly, you want code similar to the
following:

f=freefile
Open "Filename.txt" for input as #f
Do while not eof(f)
        Line Input #f, strPersonName
        List1.AddItem strPersonName    
Loop
Close f

I'm assuming here that you are reading from a text file.

Regards,

Jon Brierley



Thu, 08 Apr 1999 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Reading file name from text box and/or File List Box

2. Saving contents of a list box as a file

3. Refreshin File list box contents

4. Reading the Contents of an INI file into a combo box

5. List Box Contents to a File

6. read a file and put the contents in a text box

7. Help wanted with file list boxes and list boxes

8. Read and list mpp files in a dialogue box with VBA

9. Reading database contents into list

10. Contents of C in a list box

11. Printing the contents of a List Box

12. Showing a List Box and contents via a Command Button

 

 
Powered by phpBB® Forum Software