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

getting data from display box stored inside an associative array

Hey,

 

I'm trying to have an array that holds information as a key and display boxes as values but I can't seem to get their correct status(for checkbox) afterward- all check boxes returns as 0 even if pressed.

I cant seem to understand if that is due to a syntax issue or something deeper, here is my code:

		MainDisplayBox = V List Box();
		DisplayArray = Associative Array();
		current data table(dt);
		
		For Each Row(
			DisplayArray[char(:Col1)] = list(checkbox(""),hlist box(
				text box(char(:Col1)||": suggested value: "),
				Text Edit Box(round(:Col2,3)),
				
			));
			MainDisplayBox << append(hlistbox(eval((DisplayArray[Col1][1])),eval((DisplayArray[Col1][2]))));
		);
		
		OffsetCloseButton = Button Box("close",OffsetWindow<<Close Window);
		OffsetWindow = new window("Reticle offset analysis",vlist box(OffsetCloseButton,MainDisplayBox));
		
		keys = DisplayArray << get keys;
		pressed = list();
		for(j=1,j<=nitems(keys),j++,
			if(eval(DisplayArray[keys[j]][1])<<get==1,insert into(pressed,keys[j]));
		);

Thanks,

Ben.

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: getting data from display box stored inside an associative array

There is something wrong at least on how you are saving Combo Box references to DisplayArray. You can see it fairly easily by checking the values DisplayArray has. Check boxes are seen as:

 

Check Box("")

When they should be seen as something like this:

 

 

nw = new window("", cb = checkbox("test")); //cb = DisplayBox[CheckBoxBox]

 

So you are saving new Check Box with empty values in your DisplayArray, not a DisplayBox referencing to a check box.

 

I also think there could be simpler way to build this checkbox selection window than you currently have. Could you provide for example image and what you want it to do? For example, you are currently looping over each row in the data table with For Each Row() and then using Associative Array() to save the display boxes. Associative Array will only have one value per key, so if you have duplicated values on :Col1 you will only get the last "value".

 

Quick example using Big Class data table which might give you some ideas:

View more...
Names Default To Here(1); 
dt = Open("$SAMPLE_DATA/Big Class.jmp");

keys = Associative Array(dt:name) << get keys;

collection = Associative Array();
vlb = V List Box();

For(i = 1, i <= N Items(keys), i++,
	collection[keys[i]] = {};
	hlbTemp = H List Box(
		collection[keys[i]][1] = Check Box(""), 
		Text Box(keys[i] || ": suggested value"),
		collection[keys[i]][2] = Text Edit Box(dt:height[i])
	);
	vlb << Append(hlbTemp);	
);

//show(collection);

nw = New window("UI", << modal,
	v list box(
		vlb,
		Button Box("OK", 
			For(i = 1, i <= N Items(keys), i++,
				If(collection[keys[i]][1] << get == 1,
					Insert Into(pressed, keys[i])
				);
			);
			show(pressed);
		)
	);
);
-Jarmo

View solution in original post

2 REPLIES 2
jthi
Super User

Re: getting data from display box stored inside an associative array

There is something wrong at least on how you are saving Combo Box references to DisplayArray. You can see it fairly easily by checking the values DisplayArray has. Check boxes are seen as:

 

Check Box("")

When they should be seen as something like this:

 

 

nw = new window("", cb = checkbox("test")); //cb = DisplayBox[CheckBoxBox]

 

So you are saving new Check Box with empty values in your DisplayArray, not a DisplayBox referencing to a check box.

 

I also think there could be simpler way to build this checkbox selection window than you currently have. Could you provide for example image and what you want it to do? For example, you are currently looping over each row in the data table with For Each Row() and then using Associative Array() to save the display boxes. Associative Array will only have one value per key, so if you have duplicated values on :Col1 you will only get the last "value".

 

Quick example using Big Class data table which might give you some ideas:

View more...
Names Default To Here(1); 
dt = Open("$SAMPLE_DATA/Big Class.jmp");

keys = Associative Array(dt:name) << get keys;

collection = Associative Array();
vlb = V List Box();

For(i = 1, i <= N Items(keys), i++,
	collection[keys[i]] = {};
	hlbTemp = H List Box(
		collection[keys[i]][1] = Check Box(""), 
		Text Box(keys[i] || ": suggested value"),
		collection[keys[i]][2] = Text Edit Box(dt:height[i])
	);
	vlb << Append(hlbTemp);	
);

//show(collection);

nw = New window("UI", << modal,
	v list box(
		vlb,
		Button Box("OK", 
			For(i = 1, i <= N Items(keys), i++,
				If(collection[keys[i]][1] << get == 1,
					Insert Into(pressed, keys[i])
				);
			);
			show(pressed);
		)
	);
);
-Jarmo
Benf
Level I

Re: getting data from display box stored inside an associative array

Thanks!

Odd how the references are handled but I see your point, your approach is easier to manage with a bit of data searching in the table so it will work just fine for me.

regarding the override of data in the array - the table I was looping over was a summery so duplicates are non issue

 

Thanks again,

Ben.