明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2409|回复: 16

为什么不能写入文本?

  [复制链接]
发表于 2003-5-23 02:06:00 | 显示全部楼层 |阅读模式
我写的程序意图是:读取文本数据,使的数据中的X ,Y,H,能够同时加一个给定的常数,同时保存为原来的文本数据格式,程序运行中只能将原第二行的数据,加常数后写入新的文件中。我想是不是循环的问题,但是还是没有解决,请帮忙!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
 楼主| 发表于 2003-5-23 13:23:00 | 显示全部楼层

为什么没有高手相助呢?帮帮忙吧!

发表于 2003-5-23 14:04:00 | 显示全部楼层

你不给个文件,让人无法调试,这样必须从头将程序看懂,太费劲,

 楼主| 发表于 2003-5-23 22:13:00 | 显示全部楼层

meflying兄,我把文件及程序再上传!请帮助,多谢!

本帖最后由 作者 于 2003-5-23 22:13:47 编辑

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
发表于 2003-5-24 13:42:00 | 显示全部楼层

看看是不是这个意思

你每一行加的数值不一样吗?而且每一行都要另存一个文件吗?
另外,保存文件用参数9。
看看下面的程序能否满足你的要求
发表于 2003-5-24 13:48:00 | 显示全部楼层

1

(defun readtxt(str / lists )
  (setq lists (list (read str)))
  (setq str (vl-string-left-trim (rtos (car lists)) str))
  (setq str (vl-string-trim ", " str))
  (setq lists (append lists (list (read str))))
  (setq str (vl-string-left-trim (rtos (cadr lists)) str))
  (setq str (vl-string-trim ", " str))
  (setq lists (append lists (list (read str))))
  (setq str (vl-string-left-trim (rtos (caddr lists)) str))
  (setq str (vl-string-trim ", " str))
  (setq lists (append lists (list (read str))))
)
发表于 2003-5-24 13:48:00 | 显示全部楼层

2

(defun puttxt(f lists / n m i j str)
  (setq n (length lists))
  (setq m (length (car lists)))
  (setq i 0)
  (while (< i n)
    (setq j 1)
    (setq str (strcat (rtos (car (nth i lists))) " ,"))
    (while (< j m)
      (setq str (strcat str "," (rtos (nth j (nth i lists))) " "))
      (setq j (1+ j))
    )
    (write-line str f)
    (setq i (1+ i)))
)
发表于 2003-5-24 13:52:00 | 显示全部楼层

3

(defun c:sjjcs (/ x y h xg yg hg x_xg y_yg h_hg lists list1 ft fm fn)
  (setq file (findfile "*.txt"))
  (if (not file)
    (setq file (getfiled "\n请输入原数据文件" "e:\\" "txt;dat;*" 8))
  )
  (setq fn (open file "r"))
  (read-line fn)
  (setq ft (read-line fn))
  (setq lists nil)
发表于 2003-5-24 13:54:00 | 显示全部楼层

4(1、2、3、4、5按顺序粘贴到一个文件中,再存为*.lsp文件)

(setq xg (getreal "\n北方向加固定常数(X + <10>) :"))
  (if (null xg) (setq xg 10))
    (TERPRI)
    (setq yg (getreal "\n东方向加固定常数(Y + <20>) :"))
  (if (null yg) (setq yg 20))
    (TERPRI)
    (setq hg (getreal "\n高程加固定常数(H + <30>) :"))
  (if (null hg) (setq hg 30))
  (while ft
    (setq list1 (readtxt ft))
    (setq x (nth 1 list1))
    (setq y (nth 2 list1))
    (setq h (nth 3 list1))
发表于 2003-5-24 13:55:00 | 显示全部楼层

5

(setq x_xg (+ x xg))
    (setq y_yg (+ y yg))
    (setq h_hg (+ h hg))
    (setq list1 (list (car list1) x_xg y_yg h_hg))
    (setq lists (append lists (list list1)))
    (setq ft (read-line fn)))
  (close fn)
  (setq fm (getfiled "请指定保存新数据的路径及文件名"  "e:\\DATA1.TXT"  "txt;dat;*"  9))
  (setq n_file (open fm "w"))
  (puttxt n_file lists)
  (close n_file)
  (princ)
)
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-9-28 16:24 , Processed in 0.246880 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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