# Integers problem

Let's say I have the integers A1,A2,A3 .....Ax, and the integer x.

I want when the value of x is 2 (for example) , the caption of a label to return A2's value. If x = 3, to return A3 value and so on. How do I do that? (Without having to write manually each time if x= 2, label->caption = A2 etc, but automatically to return Ax value)

Thanks a lot.
###### Who is Participating?

Commented:
Place the integers in an array :
``````int a[10] = { 0 };          // <--- an array of 10 integers
int x = 5;
int value = a[x - 1];       // <--- the x-th value in the array
``````
0

Commented:

http://www.cplusplus.com/doc/tutorial/arrays.html
0

Commented:
See the reference to the AnsiString class at http://thunder.prohosting.com/~cbdn/pg_013.htm - you can do that like
``````AnsiString str;
int x = 2;

str = "A" + IntToStr(x);

label->caption = str;
``````
0

Data Warehouse Architect / DBACommented:
Hi Chrysaor,

You can either build the lengthy structure that you're trying to avoid, or you can use an array to contain the addres of the integers.

int A0, A1, A2, A3, A4, ..., A20;
int *A[21] = {&A0, &A1, &A2, &A3, ... &A20};

Label->Caption = Format ("%d", ARRAYOFCONST((*A[x])));

And of course, you can also skip the step of using scalar integers and putting their addresses into an array by just using an array of integers.

Good Luck,
Kent
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.