由于磁贴的值可以包含前导空格(尤其是在检索多个项目时),因此请勿将该值作为字符串比较进行测试。list_box 在处理列表框之前,首先使用函数将值转换为整数。您还可以使用 read 函数,该函数会自动将标记转换为整数。例如,对于仅接受单个选择的名为列表的列表,以下代码片段将检查是否选择了列表中的第三项:list_boxatoijustone (setq index ( get_tile "justone"))
(cond
((/= index "") ;See if string is empty.
(= 2 (atoi index))
. ; Process the third entry.
.
.
)
)
有必要首先检查字符串是否为空,因为函数为空字符串和字符串返回 0。atoi"0" 弹出列表的值从不具有前导空格,因此您不必转换该值。弹出列表不允许进行多项选择。 如果列表框支持多项选择,则程序必须进行转换并单步执行值字符串中的多个值。以下定义返回一个列表,该列表仅包含用户从原始 .(在此示例中,显示列表作为全局变量进行维护。该函数应使用列表框的当前$value进行调用:MK_LISTdisplistdisplistMK_LIST (defun MK_LIST (readlist / count item retlist)
(setq count 1)
(while (setq item (read readlist))
(setq retlist (cons (nth item displist) retlist))
(while (and (/= " " (substr readlist count 1))
(/= "" (substr readlist count 1)))
(setq count (1+ count))
)
(setq readlist (substr readlist count))
)
(reverse retlist)
)
前面的两个示例也适用于单个选择的情况。 相关概念 |
|Archiver|CAD开发者社区
( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2025-10-30 16:00
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.