subodh_gis 发表于 2022-7-5 19:54:36

写入大于32767的整数

如何使用lisp编写大于32767的文本整数。
当我键入123456时,消息是“需要一个介于-32768和32767之间的整数”

Lee Mac 发表于 2022-7-5 20:06:31

使用getreal或getstring提示用户输入,测试输入的有效性,并将其转换为整数。
 
32767限制是AutoCAD早期版本中使用16位有符号整数的结果。

subodh_gis 发表于 2022-7-5 20:13:37

谢谢李。但我不明白这是我的代码怎么办?

(defun C:kk (/ input start rot count ang inc pt1)

(setq count (getint "Enter Starting No.: "))

(if (null count) (setq count 1))
(setq inc 1)
(setq th (getint "\nEnter text height: "))
(if (null th) (setq th 1.27))

;; set continue flag to True
(setq continue T)

(while continue

(setq input (getpoint (strcat "\nInsertion point for number")))

;; evaluate user input

(cond

(T

(command "text" "s" "Standard" "mc" input 2 0 count)

(setq pt1 input)
(setq count (+ count inc)))   

)

)
(princ)
)

rkmcswain 发表于 2022-7-5 20:16:17

也许是这样?
 

(initget 5)
(setq lgint (fix (getreal "\nEnter value ")))

Lee Mac 发表于 2022-7-5 20:22:47

RK的解决方案很好-
 
或者,这里还有两个选项可以在提升16位限制的同时模拟标准getint函数的行为:
(defun mygetint ( msg / rtn )
   (while
       (and (setq rtn (getreal msg))
            (not (equal rtn (setq rtn (atoi (rtos rtn 2 0))) 1e-)
       )
       (princ "\nRequires an integer value.")
   )
   rtn
)
(defun mygetint ( msg / rtn )
   (while
       (and (setq rtn (getstring msg))
            (/='int (type (setq rtn (read rtn))))
       )
       (princ "\nRequires an integer value.")
   )
   rtn
)
(defun c:test ( )
   (mygetint "\nEnter a number: ")
)

subodh_gis 发表于 2022-7-5 20:28:17

尊敬的RK&Lee,当我输入123456时,输出为-7616

rkmcswain 发表于 2022-7-5 20:39:58

 
奇怪的它在这里起作用。
 

_$ (initget 5)
nil
_$ (fix (getreal "\nEnter value "))<---- I entered "123456" at the command prompt.
123456

subodh_gis 发表于 2022-7-5 20:47:49

也许 吧:
 


(defun C:kk (/ input start rot count ang inc pt1)

;(setq count (getint "Enter Starting No.: "))
_$ (initget 5)
nil
_$ (setq count (fix (getreal "\nEnter value ")))

(if (null count) (setq count 1))
(setq inc 1)
(setq th (getint "\nEnter text height: "))
(if (null th) (setq th 1.27))

;; set continue flag to True
(setq continue T)

(while continue

(setq input (getpoint (strcat "\nInsertion point for number")))

;; evaluate user input

(cond

(T

(command "text" "s" "Standard" "mc" input 2 0 count)

(setq pt1 input)
(setq count (+ count inc)))   

)

)
(princ)
)

marko_ribar 发表于 2022-7-5 20:50:16

你在运行什么操作系统?

Lee Mac 发表于 2022-7-5 20:58:44

页: [1]
查看完整版本: 写入大于32767的整数