2 Replies - 320 Views - Last Post: 09 May 2013 - 08:08 AM Rate Topic: -----

#1 Correctness  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 09-May 13

Using a variable in the name of an object

Posted 09 May 2013 - 12:49 AM

So say I had a program with several pictureboxes, named pic1, pic2, pic3,... and so on, is there a way to refer to specific pictureboxes by replacing the number with a variable?

i.e.
 for count = 1 to 5
         pic(count) = someimage
       next count 


Hopefully i'm explaining this well wnough
Is This A Good Question/Topic? 0
  • +

Replies To: Using a variable in the name of an object

#2 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1064
  • View blog
  • Posts: 4,166
  • Joined: 02-July 08

Re: Using a variable in the name of an object

Posted 09 May 2013 - 07:06 AM

Here is how you do it. You access them by the control collection where it allows you to use it's name.

Dim pb As PictureBox = CType(Me.Controls("pic" & count.ToString), PictureBox)
pb.Image = {some image}

This post has been edited by _HAWK_: 09 May 2013 - 07:07 AM

Was This Post Helpful? 1
  • +
  • -

#3 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9568
  • View blog
  • Posts: 36,222
  • Joined: 12-June 08

Re: Using a variable in the name of an object

Posted 09 May 2013 - 08:08 AM

Please do not create duplicate topics. closing.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1