Referring to a control with variables?

  • Thread starter Thread starter tantiboh
  • Start date Start date
T

tantiboh

I've got a situation where I'm trying to refer to a control in terms of a counter.

I've got a 4x4 grid of labels, uniformly named according to their position in the grid, I.E. lbl00, lbl01, lbl02, lbl03, lbl10, lbl11, etc.

I'd like to refer to these controls with counters so that I don't have to have 16 case statements, in a theoretical fashion such as this:

For n = 0 to 3
For 0 = 0 to 3
ControlName = "lbl" & cstr(n) & cstr(o)
AssignValue(ControlName)
Next
Next

In other words, I want to refer to a control by constructing a string. That's where I hit a wall. Is there a way to convert that string into some sort of reference to a control?

Thanks for your help!

**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
 
Hmm.. more complex than I thought it would be.

Thanks

**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
 
M,

I am curious, what is difficult on that sample?
For n = 0 to 3
For 0 = 0 to 3
ControlName = "lbl" & cstr(n) & cstr(o)
AssignValue(ControlName)
Next
Next
\\\
For n = 0 to 3
For m = 0 to 3
For Each ctr As Control In me.Controls
If ctr.Name = "lbl" & cstr(n) & cstr(o) then
AssignValue(ControlName, n, m)
end if
Next ctr
Next
Next
///
This is when your labels are direct on the form, when they are by instance
on a panel is the only difference instead of me.Controls it becomes
panelx.Controls

When you do not know where they are you need the complete sample from
Herfried.

Everything typed in this message so watch typos or other errors

I hope this helps?

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top