Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 224
  • Last Modified:

I need to refer to a text field by using a variable for its name.

Hello Experts!

I think this should be an easy question.  I've done it before but don't remember how!

I have a form that has space for 20 images.
The image "boxes" are named imgbox01, imgbox02, imgbox03 and so forth

The images that I want to display are in the array arrImage(20)

My code loops through each image in arrImages() from n=1 to 20

when I decide to display an image in a specific box, for example, imgbox2, i need to programmatically refer to this image box.

Here is an sample of my code:
'Put the image stored in location nn in the array in the imgbox specified by n
For n=1 to 20
  if <some condtion> then
     Forms!frmPhotoAlbum.Image4.Picture = arrImage(nn)
next

Only, I do not want to hard code 4 into this line, as sometimes it will go into possition 6, or whatever the value of n currently is

So, how do I incoporate the value of n into the name of the imagebox?
in other words, if n=2 how do I code so that I can replace the 4 with the value for n?
Forms!frmPhotoAlbum.Image4.Picture =arrImage(2)

0
pcalabria
Asked:
pcalabria
  • 2
1 Solution
 
Rey Obrero (Capricorn1)Commented:


use this format

Forms("frmPhotoAlbum")("Image" & n).Picture =arrImage(2)
0
 
Rey Obrero (Capricorn1)Commented:


use this format

Forms("frmPhotoAlbum")("Image" & n).Picture =arrImage(n)
0
 
GRayLCommented:
Where do you keep the number of the image in the arrray?  I assume the array element is a string, structured along the lines of:

c:\data\images\myPic.jpg
0
 
pcalabriaAuthor Commented:
Perfect!

Thanks CAP!!!
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now