12-03-2008 03:25 AM
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'
12-03-2008 03:41 AM
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
12-03-2008 03:45 AM
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 );"
12-04-2008 02:46 AM