Hey, just a quick question - Please Answer

Hey all,
I’ve been working on an Arduino project for a while now and I seemed to have run into a bit of a predicament. Within the program I have a string (that I keep redefining in a ‘for’ loop), and I would to create an integer every time the for loop iterates. My issue is I would like to use the value of the String and use that to name the integer. How would I go about doing this?

Problem is in your sketch line #134 ;)

.

I would really appreciate it if you didn't just make jokes about my question. I really am struggling to try to figure this out and any help is appreciated. Next time please don't just make a joke if you aren't going to help. Thanks

Hey all, I've been working on an Arduino project for a while now and I seemed to have run into a bit of a predicament. Within the program I have a string (that I keep redefining in a 'for' loop), and I would to create an integer every time the for loop iterates. My issue is I would like to use the value of the String and use that to name the integer. How would I go about doing this?

(deleted)

So you want to create a new variable with the size “integer” for every iteration of the loop, and the name of the variable shall NOT be hard-coded, but it should depend on the content of the string?
And the content of the string changes all the time?
I assume all these new variables are supposed to survive the end of the for loop? In other words, their scope should be one higher than the for loop?
I assume the purpose of the individual naming of the variable is so you know what the values mean?

I don’t think this is possible in the way you want to do it, but there are other ways:
Normally this is handled in the following way:

You create an array of the type integer, with as many fields as you need.
https://www.arduino.cc/en/Reference/Array

Then you simply have a cheat-sheet somewhere, where you write down, which index of the array means what. You can also put it as a comment somewhere in your code.

You can advance the index of the array with the index of the for loop:

for (int i = 0; i < number_of_iterations; i++)
{
my_array[i] = value_of_the_integer;
}

the array needs to be big enough for the number of iterations.

Be careful with creating (defining, casting) arrays automatically in functions: You can run out of memory really fast, if you lose track of your arrays.

Thomas

Hi Questioner,

Can you be more specific? I’m not really sure what you are trying to do, even after reading a few responses from folks who seem to have a better idea of what you want.

And… if you post your code we can help you more easily. Click on the </> button over the reply text box and paste your code in the block.

LarryD's crystal ball seems to be repaired recently. Lucky him, mine has been inoperative for ages now.

Why the blurry description of your problem. Are you working on some super secret project ? Show us what your have so far !

Crossposted in Project Guidance

You can guess, if we cannot see your code we have a difficult time commenting on it ;)

.

@Questioner, do not cross-post. Threads merged.