4 Replies - 6837 Views - Last Post: 16 June 2009 - 07:15 PM Rate Topic: -----

#1 pmkdatabase   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 14-June 09

How to refer to control name dynamically (VS 2005)

Posted 14 June 2009 - 05:03 AM

Hi,

I'm an Access/VBA programmer new to vb.net. In Access I can do this using the controls collection of form, but I can't figure out how or even if I can do it with vb.net.

I want to change this:
'tcpWeek(x) is a tab control page
My.Forms.frmBookMain.tcpWeek1.Text = "Mytext1" 
My.Forms.frmBookMain.tcpWeek2.Text = "Mytext2" 
etc.




To this (in pseudo code)
dim i as integer
dim strTcp as string

for i = 1 to 6 

strTcp = ="tcpWeek" & i
My.Forms.frmBookMain.strTcp.Text = "Mytext" & i 'Mytext1
 
next i 




Is This A Good Question/Topic? 0
  • +

Replies To: How to refer to control name dynamically (VS 2005)

#2 _HAWK_   User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1162
  • View blog
  • Posts: 4,444
  • Joined: 02-July 08

Re: How to refer to control name dynamically (VS 2005)

Posted 14 June 2009 - 05:16 AM

Are these tabpages made at runtime or designtime as this makes difference? And what do you want to do with them?
Was This Post Helpful? 0
  • +
  • -

#3 AdamSpeight2008   User is offline

  • MrCupOfT
  • member icon

Reputation: 2298
  • View blog
  • Posts: 9,535
  • Joined: 29-May 08

Re: How to refer to control name dynamically (VS 2005)

Posted 14 June 2009 - 05:20 AM

Here a way of doing something similar.
  For i As Integer = 1 To 5
   Me.Controls("Label" & i.ToString).Text = "I'm " & i.ToString
  Next


Was This Post Helpful? 0
  • +
  • -

#4 pmkdatabase   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 14-June 09

Re: How to refer to control name dynamically (VS 2005)

Posted 15 June 2009 - 12:24 AM

View Posthawkvalley1, on 14 Jun, 2009 - 04:16 AM, said:

Are these tabpages made at runtime or designtime as this makes difference? And what do you want to do with them?


Hi,

They are made at design time, and I want them to be labeled with the first day of the week for a (varying) set of weeks. I'm going play around with Adam's suggestion as well.
Was This Post Helpful? 0
  • +
  • -

#5 pmkdatabase   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 14-June 09

Re: How to refer to control name dynamically (VS 2005)

Posted 16 June 2009 - 07:15 PM

I can change the labeling text okay, the problem is selecting which control (tab page) dynamically, i.e.,
tcpWeek1, tcpWeek2, etc. How can I increment up the week - what is the syntax to create and then reference the control name?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1