获取大小显示框命令在我的For循环中不起作用我有一个For循环来检查V列表框中的每个文本框,并且应该返回每个文本框的大小。 由于某种原因它不会起作用:
Names Default to Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
win = New Window("Temp",
VLB = VListBox();
);
names = Column("Name") << Get Values;
//Write to window
For(j=1, j<=NItems(names), j++,
tb = TextBox(names[j]);
VLB << Append(tb);
text = VLB[j] << Get Text; //This works...
width = (VLB[j] << Get Size); //...but this just returns 0
Show(j, text, width);
);
//Nor does this work when I run with the script above, but does work if I run as a single line of code afterwards:
width = (VLB[1] << Get Size);
Show(width);正如我所指出的,“<< Get Text”命令工作正常,但不是“<< Get Size”命令。 此外,甚至在For循环之外,当我运行整个脚本时,“<< Get Size”命令不起作用。 只有在我运行其余脚本后将其作为单行代码运行才有效。
它必须与将文本框附加到VLB有关,但我无法理解它是什么。
Re:获取大小显示框命令在我的For循环中不起作用我采用了稍微不同的方法 - 我创建了一个文本框数组,并在一个单独的循环中测量它们。
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
win = New Window( "Temp", VLB = V List Box() );
names = Column( "Name" ) << Get Values;
tb = {};
//Write to window
For( i = 1, i <= N Items( names ), i++,
tb[i] = Text Box( names[i] );
VLB << Append( tb[i] );
);
For( i = 1, i <= N Items( names ), i++,
text = tb[i] << Get Text;
width = tb[i] << Get Size;
Show( i, text, width );
);
Re:获取大小显示框命令在我的For循环中不起作用谢谢大家。 wjlevin建议的Wait()命令是必不可少的。 同样获得gzmorgan0建议的单列LUB的宽度比获取单个文本框的宽度更优雅。 虽然,我发现Wait命令所需的最小长度取决于我的名字列表的长度(更长的列表=更长的等待时间)。
再次感谢。
Re:获取大小显示框命令在我的For循环中不起作用默认情况下,文本框没有固定大小,即设置了固定大小(0)。 默认情况下,大小是灵活的,规范是-1。
如果要查找名称显示的最大大小,可能需要将VLB作为单列LineUpBox(我将名称更改为LUB),并在循环结束时获取容器的宽度。
另外,使用 @wjlevin 建议等待(0)。 希望这可以帮助
Names Default to Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
win = New Window("Temp",
LUB = LineUpBox(ncol(1));
);
names = Column("Name") << Get Values;
//Write to window
For(j=1, j<=NItems(names), j++,
tb = TextBox(names[j]);
LUB << Append(tb);
);
For(j=1, j<=NItems(names), j++,
text = LUB[j] << Get Text; //This works...
width = LUB[j] << Get Width; //...but this just returns -1 meaning it is not fixed
Show(j, text, width);
);
wait(0);
MaxWidth = LUB << get width;
Show(MaxWidth);
对于我的字体大小MaxWidth = 66像素。
Re:获取大小显示框命令在我的For循环中不起作用每当我在脚本窗口中逐行运行它并且在我运行一个脚本块(特别是在某种循环中)时不能正常工作的情况下,我认为需要添加Wait( );
它不需要漫长的等待。这是我做的:
For(j=1, j<=NItems(names), j++,
tb = TextBox(names[j]);
VLB << Append(tb);
text = VLB[j] << Get Text; //This works...
wait(.01);
width = (VLB[j] << Get Size); //...but this just returns 0
Show(j, text, width);
);
这对我来说很有把戏。