明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 9235|回复: 8

[讨论] 出错在哪里?Error: 参数类型错误: (or stringp symbolp): nil

[复制链接]
发表于 2010-12-30 13:46:31 | 显示全部楼层 |阅读模式
运行程序后会出现这个错误:Error: 参数类型错误: (or stringp symbolp): nil
文本文件里的内容如下
NO1      *ce
NO2      *aar
....
....

下面是程序:
(defun c:daoru()
(setq n1 (findfile "menuini.txt"))
(setq file1 (open n1 "r"))
    (setq loop t)
    (while loop
    (setq yzh1 (read-line file1))
    (setq hang (read->biao yzh1 "*") )   
    (setq m2  (cadr hang))
    (setq m1  (car hang))   
    ;(if (= nil yzh1) (setq loop nil))
   (cond
        ((= m2 "ce") (princ "\nTHIS IS CE"))
        ((= m2 "aar") (princ "\nTHIS IS aar"))
    )
    )
(close file1)
)
;;By Longxin 明经通道 2006.03
;;以字符串为分隔符把行文字读入表中
;;例:(read->biao "jksdi,kkik,oo" ",")
;;返回:("jksdi" "kkik" "oo")
(defun read->biao (str fgf / biao s1 i)
  (setq biao nil)
  (setq i (vl-string-search fgf str))
  (while i
    (setq s1 (substr str 1 i))
    (setq str (substr str (+ 2 i)))
    (setq biao (append biao (list s1)))
    (setq i (vl-string-search fgf str))
  )
  (append biao (list str))
)



我想请问怎么样才能不让程序出错,要怎么改?





发表于 2010-12-30 14:58:54 | 显示全部楼层
调试了下,好像应该是这样吧?
(defun c:tt( / file1 hang loop m1 m2 n1 yzh1)
  (if (and (setq n1 (getfiled "选择txt文件"
                              ""
                              "txt"
                              4
                    )
           )
           ;(setq n1 (findfile "menuini.txt"))
           (setq file1 (open n1 "r"))
      )
      ;(setq loop t)
      (progn
         (while
           (setq yzh1 (read-line file1))
           (setq hang (read->biao yzh1 "*"))
           (setq m2  (cadr hang))
           (setq m1  (car hang))
           ;(if (= nil yzh1) (setq loop nil))
           (cond
               ((= m2 "ce") (princ "\nTHIS IS CE"))
               ((= m2 "aar") (princ "\nTHIS IS aar"))
           )
         )
         (close file1)
      )      
  )
  (princ)
)
;;By Longxin 明经通道 2006.03
;;以字符串为分隔符把行文字读入表中
;;例:(read->biao "jksdi,kkik,oo" ",")
;;返回:("jksdi" "kkik" "oo")
(defun read->biao (fgf str / biao s1 i)
  (setq biao nil)
  (setq i (vl-string-search fgf str))
  (while i
    (setq s1 (substr str 1 i))
    (setq str (substr str (+ 2 i)))
    (setq biao (append biao (list s1)))
    (setq i (vl-string-search fgf str))
  )
  (append biao (list str))
)
 楼主| 发表于 2010-12-30 16:51:23 | 显示全部楼层
请问是什么原因导致这个错误的了?
发表于 2010-12-30 22:04:46 | 显示全部楼层
在循环中读到文件尾时变量yzh1是nil。这时调用函数出错。
 楼主| 发表于 2010-12-31 17:47:43 | 显示全部楼层
估计也是这样,但我没办法解决,不知道你们是怎么解决的?
我用了个蠢办法
在文本最后加一个
"end"
然后判断yzh1是否是end
发表于 2010-12-31 20:57:02 | 显示全部楼层
2楼不是解决了吗。
直接用 (while (setq yzh1 (read-line file1))
判断yzh1的返回值,如果不为nil就没读到文件尾。
 楼主| 发表于 2011-1-4 09:36:46 | 显示全部楼层
我开始那样写和2楼也差不多啊!.....
发表于 2011-1-4 21:02:58 | 显示全部楼层
差得多了。
发表于 2011-1-14 08:21:43 | 显示全部楼层
学习中,新来的
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-10-2 18:34 , Processed in 0.178550 second(s), 26 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表