malix Posted April 3, 2013 Posted April 3, 2013 It has been quite a while since I wrote anything in lisp, but I am attempting to create a simple program to read some input from a dialog box and write that to a text file. Of course I will have more to add to it eventually but at this point I'm just trying to get it to write to the text file correctly. This is what i have, but I am getting the error "bad argument type: streamp nil" and I'm really not sure what is causing it. I'm stumped, if anyone could point me in the right direction I would really appreciate it. ;EDI2.lsp (defun EDI2 () (defun *error* (msg) (princ (strcat "\nError: " msg)) (reset) ) (defun reset () (unload_dialog dcl_id) (princ) ) (setq dcl_id (load_dialog "edi.dcl")) (defun write_header () (setq fname (open "C:\edi\test.txt")) (setq fdesc (open fname "w")) (write-line "po" fdesc) (write-line "oc" fdesc) (write-line "jobname" fdesc) (write-line "workorder" fdesc) (close fname) ) (defun end_setup () (setq po (get_tile "po")) (setq oc (get_tile "oc")) (setq jobname (get_tile "jobname")) (setq workorder (get_tile "workorder")) (done_dialog) (write_header) ) (if (not (new_dialog "setup" dcl_id)) (exit)) (action_tile "accept" "(end_setup)") (action_tile "cancel" "(exit)") (start_dialog) (reset) ) Quote
MSasu Posted April 3, 2013 Posted April 3, 2013 The problems are in your WRITE_HEADER function: you called the OPEN function twice, first without a mode argument; the path should be written with double backslash; also the CLOSE function have a wrong argument. (defun write_header () (setq fname [s][color=red](open[/color][/s] "C:\[color=red]\[/color]edi\[color=red]\[/color]test.txt"[s][color=red])[/color][/s]) (setq fdesc (open fname "w")) (write-line "po" fdesc) (write-line "oc" fdesc) (write-line "jobname" fdesc) (write-line "workorder" fdesc) (close [color=red]fdesc[/color]) ) On Cancel event, I would suggest you to terminate the dialog instead of forcing exit: (action_tile "cancel" "[color=red](done_dialog 0)[/color]") By the way, since you redefined the error function, a good programming practice is to retain its original state and restore it when your routine exit. Quote
malix Posted April 3, 2013 Author Posted April 3, 2013 Thanks! I made the changes you suggested but unfortunately I am getting a different error now. This time it is "bad argument type: streamp nil". ;EDI2.lsp (defun EDI2 () (defun *error* (msg) (princ (strcat "\nError: " msg)) (reset) ) (defun reset () (unload_dialog dcl_id) (princ) ) (setq dcl_id (load_dialog "edi.dcl")) (defun write_header () (setq fname "C:\\edi\\test.txt") (setq fdesc (open fname "w")) (write-line "po" fdesc) (write-line "oc" fdesc) (write-line "jobname" fdesc) (write-line "workorder" fdesc) (close fdesc) ) (defun end_setup () (setq po (get_tile "po")) (setq oc (get_tile "oc")) (setq jobname (get_tile "jobname")) (setq workorder (get_tile "workorder")) (done_dialog) (write_header) ) (if (not (new_dialog "setup" dcl_id)) (exit)) (action_tile "accept" "(end_setup)") (action_tile "cancel" "(done_dialog 0)") (start_dialog) (reset) ) Any ideas? Quote
MSasu Posted April 3, 2013 Posted April 3, 2013 Is the required folder named EDI available on drive C:? Do you have write privileges into that folder? Quote
malix Posted April 3, 2013 Author Posted April 3, 2013 That was it! The computer i was testing it on did not have an EDI folder created. Thank you very much, i think I can handle the rest of the program from here. Quote
MSasu Posted April 3, 2013 Posted April 3, 2013 Good to heat that you got it sorted. For safety, may want to add something like this to your code: (setq myPath "C:\\Edi\\") (if (not (vl-file-directory-p myPath)) (vl-mkdir myPath) ) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.