cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
ehchandler
Level V

Linked Column with ID suffix messing up column name use

I feel like I'm going a little crazy. I have a column name that I put into a variable by a column selector box. Then later on I manipulate it, but unfortunately the column is a linked column, so it comes in with a "[ID]" attached to it. That's all well and good until I try Char() on it, and suddenly escape characters appear: "{\!"Solvent[ID]\!"}". Because these characters are special, they mess-up the quotation marks, and it seems very finicky about how it handles the third question mark that is supposed to fix it. Maybe I'm putting the extra quotes in the wrong place, but I'm pretty sure I'm not based on documentation. I've tried regex, munger, substitute, Eval Expr, and nothing seems to be able to get it to the correct type that I need, which is simply a string to put into things like the column function of the by() for summarize. I feel like I'm misunderstanding something at this point, because this can't be that difficult.

 

Thanks!

Edward Hamer Chandler, Jr.
1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: Linked Column with ID suffix messing up column name use

Is there a specific reason for using List Box instead of Filter Col Selector or Col List Box? As you seem to already have validator for the inputs and there must be exactly one value chosen from both of the lists, you can just take the first index from both (<< Get Selected returns a list of strings)

jthi_0-1701791221258.png

 

majorVar = majorVar[1];
minorVar = minorVar[1];

 

 

-Jarmo

View solution in original post

4 REPLIES 4
jthi
Super User

Re: Linked Column with ID suffix messing up column name use

Why do you need to use Char on that column name? In general there should "never" be a need for it (unless you need just the name and you most likely already have it).

Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Big Class.jmp");
dt2 = Open("$SAMPLE_DATA/Big Class Families.jmp");

dt << Select Where(:name == "ROBERT") << Delete Rows << Clear Select;
dt2 << Select Where(:name == "ROBERT") << Delete Rows << Clear Select;


dt:name << Set Property("Link ID", 1);
dt2:name << Set Property("Link Reference", Reference Table("Big Class.jmp"));


nw = New Window("",
	H List Box(
		Filter Col Selector(Datatable(dt2)),
		clb = Col List Box(Datatable(dt2))
	)
);
clb << Set Items(
	{"age[name]", "sex[name]", "height[name]", "weight[name]"}
);

sel = clb << get items; // {"age[name]", "sex[name]", "height[name]", "weight[name]"}
show(sel);
show(Char(sel));
Write("\!N\!N");
Write(char(sel));
-Jarmo
ehchandler
Level V

Re: Linked Column with ID suffix messing up column name use

@jthi Thanks for the reply! So the reason I didn't just do a simple equality is because everytime I tried to access the single member column name list, I always get something along the lines of this error (its similar with other commands):

Send Expects Scriptable Object at row 1 in access or evaluation of 'Send' , clb <<  /*###*/Get( 1 ) /*###*/

I tried accessing it the way you suggested, with a get items command, but that error kept popping up. The code below shows where the variables show up first (its the majorVar and minorVar). I've never used the window:xxx syntax before, so maybe there is some way this handles variables that I don't understand?

New Window("Select Variables", << Type("Modal Dialog"),
	<<On Validate(
		window:validated
	)
,
	window:enable function = Function( {},
		{Default Local},
		majorVar = window:lbMajor << Get Selected;
		minorVar = window:lbMinor << Get Selected;
		If( N Items( majorVar ) & N Items( minorVar ) & majorVar != minorVar,
			window:validated = 1
		,
			window:validated = 0
		);
		window:ok button << Enable( window:validated )
	);
    H List Box(
        V List Box(
            Text Box("Select Major Variable"),
            window:lbMajor = List Box(combinedCols, <<Set Max Selected(1), enable function )
        ),
        V List Box(
            Text Box("Select Minor Variable"),
            window:lbMinor = List Box(combinedCols, <<Set Max Selected(1), enable function)
        )
    ),
    H List Box(
        window:ok button = Button Box("OK", 
			majorVar = window:lbMajor << Get Selected;
			minorVar = window:lbMinor << Get Selected;
			If( N Items( majorVar ) & N Items( minorVar ) & majorVar != minorVar,
				window:validated = 1
			,
				window:validated = 0
			);
            If( window:validated,
                Print("Processing with major: " || Char(majorVar) || ", minor: " || Char(minorVar));
                Window("Select Variables") << Close Window;
            ,
                Beep(); // Optional: Add a beep sound for alert
                Show("Invalid Selection");
                {window:lbMajor, window:lbMinor} << Select; window:lbMajor << Inval << Update Window;
                Wait( 0.25 );
                {window:lbMajor, window:lbMinor} << DeSelect; window:lbMajor << Inval << Update Window;
                Wait( 0.25 );
                {window:lbMajor, window:lbMinor} << Select; window:lbMajor << Inval << Update Window;
                Wait( 0.25 );
                {window:lbMajor, window:lbMinor} << DeSelect; window:lbMajor << Inval << Update Window;
            )
        ,
			<<Enable( 0 )
        )
    ,
        Button Box("Cancel", Throw("!Canceled Graph Building") )
	)
);
Edward Hamer Chandler, Jr.
jthi
Super User

Re: Linked Column with ID suffix messing up column name use

Is there a specific reason for using List Box instead of Filter Col Selector or Col List Box? As you seem to already have validator for the inputs and there must be exactly one value chosen from both of the lists, you can just take the first index from both (<< Get Selected returns a list of strings)

jthi_0-1701791221258.png

 

majorVar = majorVar[1];
minorVar = minorVar[1];

 

 

-Jarmo
ehchandler
Level V

Re: Linked Column with ID suffix messing up column name use

That worked! Thanks!

Edward Hamer Chandler, Jr.