明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 3017|回复: 3

将文本内容写入到txt文件中,用你的慧眼发现错误吧!

[复制链接]
发表于 2012-1-13 10:50:42 | 显示全部楼层 |阅读模式
1明经币
目的:将字符串写入txt文件再导入到excel中
(defun c:ed()
  (princ "\012请选择客户号和流水单号,本程序可以统计您的工作量")
  (SETQ SS(SSGET  '())
        en1 (ssname ss 0)
en2 (ssname ss 1)
  )
  (if ss
    (progn
      (setq txt1(cdr (assoc 1 (setq enl (entget en1)))))
      (setq txt1(vl-string-right-trim " " txt1)
     txt1(vl-string-right-trim "\n\t" txt1)
     txt1(stre txt1 50);此处已不能正确运行,若注释掉可正常运行,但最好每个字符串的长度都可以定义,方便导入excel
      )
      (setq txt2(cdr (assoc 1 (setq enl (entget en2)))))
      (setq txt2(vl-string-right-trim " " txt2)
     txt2(vl-string-right-trim "\n\t" txt2)
     ;txt2(stre txt2 50)
      )
      (setq gcl_time_rq(nth 6 (my_date)))
      ;(setq gcl_time_rq(stre gcl_time_rq 50))
      (setq gcl_time_sfm(nth 7 (my_date)))
      ;(setq gcl_time_sfm(stre gcl_time_sfm 50))
      (setq gcl_name(getvar "dwgname"))
      ;(setq gcl_name(stre gcl_name 100))
      (setq gcl_gcs "明经通道                    新年好")
      (setq lasttxt(strcat gcl_time_rq
      gcl_time_sfm
             txt1
             txt2
             gcl_name
             gcl_gcs)
      )
      (setq f (open "d:\\工作量统计\\工作.txt" "a"))
      (write-line lasttxt f)
      (close f)
      (princ "你的工作已被统计,十分感谢您的辛勤工作!")(prin1)
      );end progn
    (alert "\012你的工作量没有被统计,请核查!")
  );end if
  
);end defun

;用于生成制图日期
(DEFUN MY_DATE( / TMP Y M D H MINUTE SECOND NYR SFM TXT)
(setq tmp (rtos (getvar "cdate") 2 8)         
y   (rtos (atof (substr tmp 1 4)) 2 0)
m   (rtos (atof (substr tmp 5 2)) 2 0)
d   (rtos (atof (substr tmp 7 2)) 2 0)
        h   (rtos (atof (substr tmp 10 2)) 2 0)
        minute (rtos (atof (substr tmp 12 2)) 2 0)
        second (rtos (atof (substr tmp 14 2)) 2 0)
nyr (strcat y "-" m "-" d)
sfm (strcat h ":" m ":" d)
txt (strcat  y "-" m "-" d "-" h "-" minute "-" second)
  )
  (LIST Y M D H MINUTE SECOND NYR SFM TXT);返回九个值
);EDN DEFUN
;函数stre将字符串str用@补至e长度
;qwertyuiop  15=>"qwertyuiop@@@@@"用空格补至15个字符长度
(defun stre(str e / nn)
  (setq nn(strlen str))
  (if (> e nn)
    (progn
      (repeat (- e nn)
        (setq str(strcat str "@")
        )
      )
    )
    (princ "\012您给定的字符串长度太短!")
  )
  (prin1)
)

最佳答案

查看完整内容

函数STRE没有设定返回值。 (defun stre(str e / nn) (setq nn(strlen str)) (if (> e nn) (progn (repeat (- e nn) (setq str(strcat str "@") ) ) ) (princ "\012您给定的字符串长度太短!") ) (prin1) str ;;;>>>>>>>>>>>>>>>>>>>>>>>> ADD THIS ) 另外,可以精简函数 (Defun stre (str e) (while (< (strlen str) e)(setq str (strcat str "@"))) str)
"觉得好,就打赏"
还没有人打赏,支持一下
发表于 2012-1-13 10:50:43 | 显示全部楼层

,

本帖最后由 mmmmmm 于 2012-1-13 11:34 编辑

函数STRE没有设定返回值。
(defun stre(str e / nn)
  (setq nn(strlen str))
  (if (> e nn)
    (progn
      (repeat (- e nn)
        (setq str(strcat str "@")
        )
      )
    )
    (princ "\012您给定的字符串长度太短!")
  )
  (prin1)
str ;;;>>>>>>>>>>>>>>>>>>>>>>>> ADD THIS
)
另外,可以精简函数
(Defun stre (str e) (while (< (strlen str) e)(setq str (strcat str "@"))) str)
回复

使用道具 举报

 楼主| 发表于 2012-1-13 11:41:31 | 显示全部楼层
mmmmmm 发表于 2012-1-13 10:50
函数STRE没有设定返回值。
(defun stre(str e / nn)
  (setq nn(strlen str))

参数类型错误: stringp
还有错误呀!只要注释掉txt1(stre txt1 50)就行了,只是字符串间没有@间隔,为什么呢?
回复

使用道具 举报

发表于 2012-1-14 12:39:49 | 显示全部楼层
;函数stre将字符串str用@补至e长度 ,后面 补个返回值 就可以了.
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-5-14 07:33 , Processed in 0.200250 second(s), 29 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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