07-07-2015 09:59 AM
Dear all,
I have a question for programming an issue with C/Labwindows and I need a help if it is possible.
I have consts named : A_0, A_1 and I would like to access to these const automatically. Meanning that I would like to create a const name wich is the result of concatination of the string «A_» with a number. The resulted concatination gives me the name of the const which I can use to access a position of an array for example.
Example :
Consts which already exisit :
#define A_0 0
#define A_1 1
#define A_2 2
…..
…..
#define A_100 100
I need to access to these consts automtically.
« A_» concatinated with «0», it gives a string « A_0 ». Then the resulted string « A_0 » will be used as a const which I can use to access an array for example (Array[A_0]=0, Array[A_1]=1,…).
I would like to know if there is some ideas to do this feature.
Thank you so much for your answer,
Best regards,
--
Hapiest
Solved! Go to Solution.
07-08-2015 09:26 AM
I would like to know if somone has an idea for the issue that I have described.
Thank you for your answer.
Best regards,
--
Hapiest
07-08-2015 09:44 AM
I dont' think yoo can obtain what you are describing: #define is a preprocessor clause that is evaluated at compile time (not at runtime) substituting the macro name with the corresponding value before compiling and linking the program.
The closest method I can think of is some form of array type that you can use by its index, but with no additional information on what is your goal it's hard to design a real system.
07-08-2015 10:32 AM
Thank you for your answer.
The real system is:
I have many(100) check box object in my user interface. When these check boxes are insered in the my interface, it will be a generation of thes const variables in the ".h" file, automatically (with #define...).
So the issue is that I would like check or uncheck these chek boxes following a variable value "v". If (v ==1), then I will check all the check boxes. If (v==0), then I will uncheck all the check boxes.
The name of check boxes are A_0, A_1.....A_99.
07-08-2015 11:01 AM
07-08-2015 06:25 PM - edited 07-08-2015 06:26 PM
Control arrays suggested by wolfgang are a powerful tool indeed. They help solving several control addressing problems.
Before they were introduced you could simply create arrays of control ID'S and use them, this way:
int ctl [100]; // fill in the array ctl [0] = PANEL_CHECKBOX1; ... CTL [99] = PANEL_CHECKBOX100; // Use the array in a loop for (i=0; i < 99; i++) { SetCtrlVal (panel Handle, ctl [i], 1); }
07-09-2015 04:51 AM
Control arrays is what I am looking for!
Creating an array of controls resolves also the issue!
Thank you!
--
Hapiest