Get Size Display Box Command will not work in my For LoopI have a For loop that inspects each text box in a V List Box, and is supposed to return the size of each. For some reason it will not work though:
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);As I indicated, the " << Get Text" command works fine, but not the " << Get Size" command. Also, and even outside the For loop, the " << Get Size" command does not work when I run the whole script. Only if I run it as a single line of code after I've run the rest of the script will it work.
It must have something to do with appending the textboxes to VLB, but I can't understand what it is.
Re: Get Size Display Box Command will not work in my For LoopI took a slightly different approach - I created an array of text boxes and measured them in a separate loop.
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: Get Size Display Box Command will not work in my For LoopThanks all. The Wait() command suggested by wjlevin was essential. Also getting the width of the single-column LUB as suggested by gzmorgan0 was more elegant than getting the widths of individual text boxes. Although, I found the the minimum length needed for the Wait command was dependent on the length of my names list (longer list = longer wait time).
Thanks again.
Re: Get Size Display Box Command will not work in my For LoopBy default a Text Box does not have Fixed Size, that is Fixed Size(0) is set. By default is the size is flexible, the specification is -1.
If you are looking for the max size of the name display, you might want to make VLB a single column LineUpBox ( I changed the name to LUB), and at the end of the loop get the width of the container.
Also, use @wjlevin suggestion to Wait(0). Hope this helps
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);
For my font size MaxWidth = 66 pixels.
Re: Get Size Display Box Command will not work in my For LoopWhenever I have a situation where it works when I run it line-by-line from the script window and doesn't work when I run a block of script (particularly within some kind of loop) I figure there's a need for adding Wait();
And it doesn't have to be a long wait. Here's what I did:
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);
);
That did the trick for me.