Accessing a control by name

  • Thread starter Thread starter Jack Russell
  • Start date Start date
J

Jack Russell

If I know the name of a control can I access it (change its text etc)
without looking through all the controls for one with this name?

Thanks

Jack Russell
 
Jack:

Absolutely!

myTextBox.Text = "I changed the text value"

will do just that!

Am I missing something?
 
Sorry should have been more explicit, I have the name as a string.
So dim s as string
s="label1"
Now I want to say s.text="Hello"
Jack:

Absolutely!

myTextBox.Text = "I changed the text value"

will do just that!

Am I missing something?

:
S
 
Sorry Herfried, I should have been more explicit. I was hoping I could
get to it directly without searching the array. Guess that is what I
will have to do.

Jack
 
Jack said:
If I know the name of a control can I access it (change its text etc)
without looking through all the controls for one with this name?

Thanks

Jack Russell

you could make a hashtable of the controls you want access to and look
it up that way.

Chris
 
Jack,
So dim s as string
s="label1"
Now I want to say s.text="Hello"
This is a typical scrypting language feature which is not as simple as this
in VB.Net.

In fact there is no need for it, you know all the labels which are in your
classes either by indice or eiter by there internal name.

It does not help

Cor
 
Cor said:
Jack,



This is a typical scrypting language feature which is not as simple as this
in VB.Net.

In fact there is no need for it, you know all the labels which are in your
classes either by indice or eiter by there internal name.

It does not help

Cor
Cor,

For rather obscure reasons I am trying to write a simple text file of
all the controls and their text so that a dumb user can edit it and I
read it back. Anyway, I have got it working the long way.
Thanks for your help
Jack
 
Jack,
For rather obscure reasons I am trying to write a simple text file of all
the controls and their text so that a dumb user can edit it and I read it
back. Anyway, I have got it working the long way.
Thanks for your help


Than you know the "name" from that label and can you find it using one of
those methods Herfried has showed. An alternative is using the tag, which
makes your less dependend when you have changes. However that is only an
extention from the methods Herfried probably shows (I don't have to look to
it, to know what those are).

Don't think looping is slow in VBNet. It is that fast that every other
method takes often so many overhead, that looping outclasses it almost
forever.

I hope this helps,

Cor
 
Cor said:
Jack,





Than you know the "name" from that label and can you find it using one of
those methods Herfried has showed. An alternative is using the tag, which
makes your less dependend when you have changes. However that is only an
extention from the methods Herfried probably shows (I don't have to look to
it, to know what those are).

Don't think looping is slow in VBNet. It is that fast that every other
method takes often so many overhead, that looping outclasses it almost
forever.

I hope this helps,

Cor
Cor,

Thanks, your advice is always welcome. I will probably have some more
questions as it goes along.

Jack
 
Jack Russell said:
Sorry Herfried, I should have been more explicit. I was hoping I could
get to it directly without searching the array. Guess that is what I
will have to do.

An alternative way is using a hashtable, as shown in the article.
 
Back
Top