我在获取用户输入并将其转换为变量时遇到问题。我尝试使用的脚本粘贴在本段下面。我已经多次运行相同的脚本,而没有对其进行编辑,则在日志中得到两个不同的结果。该脚本如下:
names default to here(1);
clear log();
close all(journals, no save);
close all(data tables, no save);
defuplim = format(today(),"ddMonyyyy");
deflowlim = format(today() - in days(730), "ddMonyyyy");
New Window("Pick Your Dates in ddMonyyyy format",
<<Modal,
<<return result,
V List Box(
Text Box("Start Date:"),
str1=Text Edit Box(deflowlim),
text box("End Date:"),
str2=Text Edit Box(defuplim)
),
H List Box (Button Box ("OK"), Button Box ("Cancel"))
);
lowlim = str1 << get text;
uplim = str2 << get text;
lowlim=informat(lowlim);
uplim= informat(uplim);
show (lowlim);
show (uplim);
日志的第一个结果是我期望脚本生成的结果,并将其复制并粘贴在下面的引号中:
“
lowlim = 2015年1月19日;
uplim = 2017年1月18日;
“
我从日志中获得的另一个响应(再次完全不编辑脚本)是:
“
删除的对象引用:str2 <<获取访问或评估“胶水”的文本,名称默认为Here(1); /*###*/清除日志(); / * ### * /
全部关闭(日记,不保存); / * ### * /关闭全部(数据表,不保存); / * ### * /
defuplim = Format(Today(),“ ddMonyyyy”); / * ### * / deflowlim =
Format(Today()-In Days(730),“ ddMonyyyy”); / * ### * /
新窗口(“以ddMonyyyy格式选择日期”,
<<模态
<<返回结果,
V列表框(
文本框(“开始日期:”),
str1 =文本编辑框(deflowlim),
文本框(“结束日期:”),
str2 =文字编辑框(defuplim)
),
H列表框(按钮框(“确定”),按钮框(“取消”))
); / * ### * / lowlim = str1 <<获取文本; / * ### * / uplim = str2 <<获取文本; / * ### * / lowlim
= Informat(lowlim); / * ### * / uplim = Informat(uplim); / * ### * / Show(lowlim); / * ### * /
显示(uplim)/ * ### * /;
在以下脚本中,错误标记为/ * ### * /
名称默认为Here(1); /*###*/清除日志(); / * ### * /
全部关闭(日记,不保存); / * ### * /关闭全部(数据表,不保存); / * ### * /
defuplim = Format(Today(),“ ddMonyyyy”); / * ### * / deflowlim =
Format(Today()-In Days(730),“ ddMonyyyy”); / * ### * /
新窗口(“以ddMonyyyy格式选择日期”,
<<模态
<<返回结果,
V列表框(
文本框(“开始日期:”),
str1 =文本编辑框(deflowlim),
文本框(“结束日期:”),
str2 =文字编辑框(defuplim)
),
H列表框(按钮框(“确定”),按钮框(“取消”))
); / * ### * / lowlim = str1 <<获取文本; / * ### * / uplim = str2 <<获取文本; / * ### * / lowlim
= Informat(lowlim); / * ### * / uplim = Informat(uplim); / * ### * / Show(lowlim); / * ### * /
显示(uplim)/ * ### * /;
“
我已经在前四行中切换为打开和关闭状态,但是无论它们是关闭还是打开,都得到相同的结果(混合响应)。
有什么想法可能导致此错误吗?
谢谢,这非常有帮助!将日期保持为数字很有意义,并且需要较少的转换。
txnelson的脚本是处理日期的更好方法,此外,它还通过在框中获取值来解决您的脚本遇到的核心问题。
在脚本中,创建一个模态新窗口,但是在关闭窗口后,尝试从窗口的显示框中获取信息。窗口关闭后,您将无法再访问其保存的内容-它不再存在。这就是为什么您收到lowlim = str1 << get text;的语法错误的原因。
但是,您几乎已经到了-您为模态窗口指定了返回结果,但是您没有使用从窗口中得到的结果。
无需进行任何其他更改(尽管txnelson的日期处理效果更好),您可以通过将New Window分配给变量,然后获取这些值(下面的红色更改)来获得所需的内容:
ww = New Window("Pick Your Dates in ddMonyyyy format",
<ww["str1"];
uplim = ww["str2"];
尝试使用此版本....它将日期保留为数字,这是JMP首选的方式
Names Default To Here( 1 );
Clear Log();
Close All( journals, no save );
Close All( data tables, no save );
defuplim = Today();
deflowlim = Today() - In Days( 730 );
New Window( "Pick Your Dates in ddMonyyyy format",
<<MODAL></MODAL>