Help with reading text file into dcl listbox

Help with reading text file into dcl listbox

DC-MWA
Collaborator Collaborator
1,426 Views
5 Replies
Message 1 of 6

Help with reading text file into dcl listbox

DC-MWA
Collaborator
Collaborator

Hi all,

Trying to read from a text file into a dcl list box.

Can't seem to get it to work. I have attached the lisp and my attempts within.

I'm guessing this is just something obvious I'm missing.

 

-dc

 

0 Likes
Accepted solutions (1)
1,427 Views
5 Replies
Replies (5)
Message 2 of 6

SeeMSixty7
Advisor
Advisor
Accepted solution

Updated these two sections of your code

(setq myList1 (list)) 
(setq openfile (open "TEST2.txt" "r"))
(while (setq line (read-line openfile))
   (setq txtlist (append txtlist (list line)))
)
(close openfile)

and instead of using mapcar used a foreach.

	   (start_list "mylist1")
	   (foreach txtline txtlist (add_list txtline))
	   (end_list)

It works fine now

 

 

0 Likes
Message 3 of 6

dlanorh
Advisor
Advisor

See if this works (not tested)

 

(setq myfile "TEST2.txt")
(setq myList1 nil) ;NIL is a list you can test by using (listp nil). This avoids null strings ("") in lists of text 
(cond ( (findfile myfile) 
        (setq openfile (open myfile "r"))
        (while (setq line (read-line openfile))
          (setq myList1 (cons line myList1))
        );end_while
        (close openfile)
      )
      (t (alert (strcat "File " myfile " NOT Found")))
);end_cond

 

Then later

 

 (start_list "mylist1" 3);; The 3 is not needed as this is the default if omitted
 (mapcar 'add_list (reverse myList1))
 (end_list)

 

I am not one of the robots you're looking for

0 Likes
Message 4 of 6

DC-MWA
Collaborator
Collaborator

thank you.

0 Likes
Message 5 of 6

DC-MWA
Collaborator
Collaborator

thank you for your input. I'm trying this as well.

0 Likes
Message 6 of 6

SeeMSixty7
Advisor
Advisor

You are very welcome!

0 Likes