LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to assign


 

Hello All,

 

I am a begineer in Labwindws and need help in the following scenario. The below two images shows an xml file with attributes and boxes which needs to be filled with label in the XML file.

I need to import the XML file at runtime and change all the boxes label to the new ones mentioned in the XML file. I can do that one by one by setting

 

SetCtrlAttribute (panelHandle, PANEL_TOGGLEBUTTON_1, ATTR_ON_TEXT, text);

SetCtrlAttribute (panelHandle, PANEL_TOGGLEBUTTON_2, ATTR_ON_TEXT, text);

 

Since there are multiple boxes as such, how can I define PANEL_TOGGLEBUTTON by some string name for e.g. "id" so that I can iterate through the loop and assign the XML "id" attribute to my control (TOGGLEBUTTON ) and can replace the label.

 

Many Thanks,

Raunak

 

NIcomXML.PNG

NIcom_LED.PNG

0 Kudos
Message 1 of 4
(3,923 Views)

Hi Raunak,

 

I hope you are enjoying your experience with CVI. What you are trying to do is definitely achievable. The key here is Control ID is an int and not a string

int SetCtrlAttribute (int Panel_Handle, int Control_ID, int Control_Attribute, ...);

 

After you generate the code for your .uir file in CVI (Code>>Generate>>All Code...) look at the corresponding header (.h) file. It should have a list of #define values at the top that should look something like

#define PANEL                      1

#define PANEL_TOGGLEBUTTON_1       2

#define PANEL_TOGGLEBUTTON_2       3 

...

#define PANEL_TOGGLEBUTTON_N       N+1

 

If you want to iterate over these values make sure that they are in order and iterate over the range. You might have to reassign some of the values generated. In the above example, you would iterate between 2 and N+1.

 

Good luck with your application. Welcome to CVI!

JD B.
Applications Engineer
National Instruments
0 Kudos
Message 2 of 4
(3,906 Views)

There has been an interesting discussion about JDragon suggestion a few years ago that in my opinion can be of help in understanding pros and cons about it.

As can be read in that thread, my opinion at that time was not to rely on control tab order but create an array of control IDs to use in addressing controls. This suggestion remains valid and you can see in the discussion I link how to use it.

 

The introduction of control arrays in CVI2010 has furtherly simplified the matter in that instead of manually creating and filling the array of control IDs, you can create a control array out of the controls you want to customize and address them in a loop this way:

int	i, nCtrls, aryH;

aryH = GetCtrlArrayFromResourceID (panelHandle, CTRLARRAY);
GetNumCtrlArrayItems (aryH, &nCtrls);
for (i = 0; i < nCtrls; i++) {
	SetCtrlAttribute (panelHandle, GetCtrlArrayItem (aryH, i), ATTR_ON_TEXT, text[i]);
}

This in the hypothesis that elements in the control array are ordered as the collection of strings you are using. The order of controls in the array can be arranged in the UIR editor.

Informations on the control arrays can be found in CVI help and some examples are available (e.g. samples\userint\ledctrlarray.prj).



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 3 of 4
(3,891 Views)

Thank you Guys. This is what I want.

0 Kudos
Message 4 of 4
(3,875 Views)