# Opening numbered images

**URL:** <https://discourse.processing.org/t/opening-numbered-images/44791>\
**Category:** Coding Questions\
**Created:** [July 21, 2024, 2:34pm UTC](https://discourse.processing.org/t/opening-numbered-images/44791 "2024-07-21T14:34:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![fra](https://avatars.discourse-cdn.com/v4/letter/f/a6a055/32.png) [@fra](https://discourse.processing.org/u/fra)\
**Post date:** [July 21, 2024, 2:34pm UTC](https://discourse.processing.org/t/opening-numbered-images/44791/1 "2024-07-21T14:34:10Z")

</div>

Hi,

in a folder I saved three .png files:  
“1.png”, “2.png”, “3.png”

In the Processing code I use a constant:  
`int A = 3;`

Now: I would like open an “A.png” image , with A set by the variable above.  
So, for example:  
`int A = 3; img = loadImage("A.png"); => the "3.png" image opens`

So a code like this (which obviously doesn’t work):

```auto
size(400,400);
int A = 3;
PImage img;
img = loadImage("A.png");
image(img, 0, 0);

```

By starting the sketch, the “3.png” image should open.  
Any tips?  
Thank you,  
f

---

<div class="post-metadata">

**Author:** ![eightohnine](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/eightohnine/32/19793_2.png) [@eightohnine](https://discourse.processing.org/u/eightohnine)\
**Post date:** [July 21, 2024, 2:50pm UTC](https://discourse.processing.org/t/opening-numbered-images/44791/2 "2024-07-21T14:50:46Z")

</div>

`img = loadImage("A.png");`

Anything inside of those quotation marks will be treated as a string only. So that “A” is not seen as a variable, but instead is just a character in a longer string.

Instead, **concatenation** is your friend here.

You use the “+”-symbol to concatenate/combine two or more parts together. In your case, the variable part (A) and the string part (“.png”). Slap the + between the two parts and you get:

`img = loadImage(A+".png");`

On runtime, this concatenation will resolve into “3.png”. (If the value of A is 3).

---

<div class="post-metadata">

**Author:** ![eightohnine](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/eightohnine/32/19793_2.png) [@eightohnine](https://discourse.processing.org/u/eightohnine)\
**Post date:** [July 21, 2024, 2:57pm UTC](https://discourse.processing.org/t/opening-numbered-images/44791/3 "2024-07-21T14:57:34Z")

</div>

> [@fra](#):
>
> In the Processing code I use a constant:  
> `int A = 3;`

Also, this is not a _constant_. The value of a constant doesn’t (or isn’t supposed to) change while running the sketch.  
For your use-case, this is a **variable** , because it’s meant to hold variable/changing values.

I’m obviously being nit-picky here, but better to get the basic wordings down early and prevent confusion down the line.

---

<div class="post-metadata">

**Author:** ![fra](https://avatars.discourse-cdn.com/v4/letter/f/a6a055/32.png) [@fra](https://discourse.processing.org/u/fra)\
**Post date:** [July 21, 2024, 4:32pm UTC](https://discourse.processing.org/t/opening-numbered-images/44791/4 "2024-07-21T16:32:44Z")

</div>

> [@eightohnine](#):
>
> img = loadImage(A+“.png”);

Yes, this is the solution.  
Thank you very much,  
f

---

<div class="post-metadata">

**Author:** ![fra](https://avatars.discourse-cdn.com/v4/letter/f/a6a055/32.png) [@fra](https://discourse.processing.org/u/fra)\
**Post date:** [July 21, 2024, 4:36pm UTC](https://discourse.processing.org/t/opening-numbered-images/44791/5 "2024-07-21T16:36:32Z")

</div>

> [@eightohnine](#):
>
> Also, this is not a _constant_.

You are right, I was imprecise in writing.  
“A” _must_ be a variable, because it will then receive numbers via OSC, stored in “A” for use in opening images.  
Bye,  
f
