LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Variable as string

Solved!
Go to solution

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

0 Kudos
Message 1 of 7
(5,510 Views)

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

0 Kudos
Message 2 of 7
(5,466 Views)

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.



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?
0 Kudos
Message 3 of 7
(5,457 Views)

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.

 

0 Kudos
Message 4 of 7
(5,447 Views)
Solution
Accepted by topic author hapiest

Did you consider using control arrays? See here or here?

 

Another possibility is to create the UI controls programmatically at run-time

Message 5 of 7
(5,442 Views)
Solution
Accepted by topic author hapiest

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);
}

 



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 6 of 7
(5,424 Views)

Control arrays is what I am looking for!

Creating an array of controls resolves also the issue!

Thank you!

--

Hapiest

0 Kudos
Message 7 of 7
(5,386 Views)