BookmarkSubscribe
Choose Language Hide Translation Bar
DjakFrost
New Contributor

Update NE Box from Cell in Same Row of Table Referenced by Combo Box

Hello all

 

I've been trying to update a script handed down to me, and while I've had a lot of success with it, one item keeps tripping me up. Instead of having users enter a height and width (used later in the script to generate a bivariate map), I want to have the option to auto-poplulate those values in number edit boxes (in case the user still wants to input the values manually) based on the values that correspond to a part name in a table. Modifying the example I found, it would be something like this:

 

dt = Open( "$SAMPLE_DATA\Big Class.jmp" );
Summarize( a = By( :name ) );
Insert Into( a, "<Select Name>", 1 );
New Window( "Example",
	<<Modal,
	H List Box(
		/* Upon selecting a name, populate the Number Edit Boxes with corresponding age/weight */
		Panel Box( "Select a Name:",
			cb1 = Combo Box(
				a,
				<<SetFunction(
					Function( {this},
						selection = this << Get Selected();
						r = dt << Get Rows Where( :name == Num( selection ) );
						NameAge = :age[r];
						ne1 << Set Items( NameAge );
					)
				);
				<<SetFunction(
					Function( {that},
						selection2 = that << Get Selected();
						q = dt << Get Rows Where( :weight == Num( selection2 ) );
						NameWeight = :weight[q];
						ne2 << Set Items( NameAge );
					)
				);
			)
		),
		Panel Box( "Select an Age:",
			ne1 = Number Edit Box(
				<<SetFunction(
					Function( {this},
						Print( selection, this << Get Selected() )
					)
				)
			)
		),
		Panel Box( "Select a Weight:",
			ne2 = Number Edit Box(
				<<SetFunction(
					Function( {that},
						Print( selection2, that << Get Selected() )
					)
				)
			)
		),
	)
);

 

 

0 Kudos
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
DjakFrost
New Contributor

Re: Update NE Box from Cell in Same Row of Table Referenced by Combo Box

Well, after a lot of trial and error, I eventually figured it out. The problem was trying to set a number in the number edit box. It ended up being easier—for me, at least—to make the number a string and set text, converting it back to num when it's retrieved. It ended up looking something (but not at all, heh) like this:

 

dt = Open( "$SAMPLE_DATA\Big Class.jmp" );
Summarize( a = By( :name ) );
Insert Into( a, "<Select Name>", 1 );
NameAge = "--";
NameWeight = "--";

New Window( "Example",
<<Modal,
H List Box(
/* Upon selecting a name, populate the Number Edit Boxes with corresponding age/weight */
Panel Box( "Select a Name:",
cb1 = Combo Box(
a,
<<SetFunction(
Function( {this},
selection = this << Get Selected();
dt << Select Where( :name == char( selection ) );
NameAgeList = ( :Age[dt << get selected rows]);
NameWeightList = ( :Weight[dt << get selected rows]);
NameAge = char(NameAgeList[1]);
NameWeight = char(NameWeightList[1]);
tb1 << Set Text (NameAge);
tb2 << Set Text (NameWeight)
)
)
)
),
Panel Box( "Age:",
tb1 = Text Box(NameAge)
),
Panel Box( "Weight:",
tb2 = Text Box(NameWeight)
)
),
Button Box("OK",
AgeIsh = tb1 << Get Text();
Age = Num(AgeIsh);
WeightIsh = tb2 << Get Text();
Weight = Num(WeightIsh); 
)
);

Likely not the most elegant solution, but hey.

0 Kudos
1 REPLY 1
Highlighted
DjakFrost
New Contributor

Re: Update NE Box from Cell in Same Row of Table Referenced by Combo Box

Well, after a lot of trial and error, I eventually figured it out. The problem was trying to set a number in the number edit box. It ended up being easier—for me, at least—to make the number a string and set text, converting it back to num when it's retrieved. It ended up looking something (but not at all, heh) like this:

 

dt = Open( "$SAMPLE_DATA\Big Class.jmp" );
Summarize( a = By( :name ) );
Insert Into( a, "<Select Name>", 1 );
NameAge = "--";
NameWeight = "--";

New Window( "Example",
<<Modal,
H List Box(
/* Upon selecting a name, populate the Number Edit Boxes with corresponding age/weight */
Panel Box( "Select a Name:",
cb1 = Combo Box(
a,
<<SetFunction(
Function( {this},
selection = this << Get Selected();
dt << Select Where( :name == char( selection ) );
NameAgeList = ( :Age[dt << get selected rows]);
NameWeightList = ( :Weight[dt << get selected rows]);
NameAge = char(NameAgeList[1]);
NameWeight = char(NameWeightList[1]);
tb1 << Set Text (NameAge);
tb2 << Set Text (NameWeight)
)
)
)
),
Panel Box( "Age:",
tb1 = Text Box(NameAge)
),
Panel Box( "Weight:",
tb2 = Text Box(NameWeight)
)
),
Button Box("OK",
AgeIsh = tb1 << Get Text();
Age = Num(AgeIsh);
WeightIsh = tb2 << Get Text();
Weight = Num(WeightIsh); 
)
);

Likely not the most elegant solution, but hey.

0 Kudos