獲取大小顯示框命令在我的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);
);
這對我有用。