LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Variable name based on another variable value

Hello,

 

I would like to know if is it possible to set a variable name according to the content of another variable value:

To do something like

 

int VariableForValue;

for (VariableForValue=0; VariableForValue<10; VariableForValue++) {

    SetCtrlVal(panel,PANEL_VAL_VariableForValue,VariableForValue);

}

 

Best regards,

Mat'

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

Hi Mat'

you can do things like that for the control-ID you pass in SetCtrlVal is an integer.

 

Your sniplet should look like

 

for (VariableForValue=0; VariableForValue<10; VariableForValue++) {

    SetCtrlVal(panel,PANEL_VAL_START+VariableForValue,VariableForValue); 

}

 

There is one condition to get that working: all controls you want to set (or get) by this loop must be in consecutive tab-order! You can set the ta-order of the elements in you uir in the gui editor(Edit | Tab order (Ctrl-T)).

 

hth

ah

 

 

0 Kudos
Message 2 of 4
(3,590 Views)

are you saying that you are missing arrays of controls on CVI panels ? (NI people listening ? we have no control over control ids, no way to group controls into arrays...)

 

what you are trying to achieve is not entirely possible. you can use the preprocessor to generate variable names by using the (almost unknown) token pasting operator: ##.

but you can not perform a loop using the preprocessor (you may find some other way to avoid the loop). of course, since it is using the preprocessor, all the code is generated at compile time: the number of controls cannot be adjusted at runtime.

 

a very good example, very close to your problem can be seen on wikipedia here.

 

another way is to create the controls at runtime. there is a tool in the installation directory of CVI to convert panels to code. you could use it to generate the necessary code to create your panel, and correct the code to place the control handles into an array. then you could write: "for ( i = 0; i < 10; i++ ) SetCtrlVal( panel, control[i], i );"

0 Kudos
Message 3 of 4
(3,587 Views)
If you can't or don't want to change the tab order, you could build an index of the control names via ATTR_CONSTANT_NAME after loading/creating the panel(s) and maybe work with that.
-----------------------
/* Nothing past this point should fail if the code is working as intended */
0 Kudos
Message 4 of 4
(3,553 Views)