Connecting Tech Pros Worldwide Help | Site Map

Accessing a control by name

Jack Russell
Guest
 
Posts: n/a
#1: Nov 23 '05
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
Herfried K. Wagner [MVP]
Guest
 
Posts: n/a
#2: Nov 23 '05

re: Accessing a control by name


"Jack Russell" <jackr@norubbish.tpg.com.au> schrieb:[color=blue]
> 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?[/color]

Accessing controls by their names or indices
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=controlbynameindex&lang=en>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
vvenk
Guest
 
Posts: n/a
#3: Nov 23 '05

re: Accessing a control by name


Jack:

Absolutely!

myTextBox.Text = "I changed the text value"

will do just that!

Am I missing something?

"Jack Russell" wrote:
[color=blue]
> 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
>[/color]
Jack Russell
Guest
 
Posts: n/a
#4: Nov 23 '05

re: Accessing a control by name


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"

vvenk wrote:[color=blue]
> Jack:
>
> Absolutely!
>
> myTextBox.Text = "I changed the text value"
>
> will do just that!
>
> Am I missing something?
>
> "Jack Russell" wrote:
>
>[color=green]
>>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
>>[/color][/color]
S
Jack Russell
Guest
 
Posts: n/a
#5: Nov 23 '05

re: Accessing a control by name


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


Herfried K. Wagner [MVP] wrote:
[color=blue]
> "Jack Russell" <jackr@norubbish.tpg.com.au> schrieb:
>[color=green]
>> 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?[/color]
>
>
> Accessing controls by their names or indices
> <URL:http://dotnet.mvps.org/dotnet/faqs/?id=controlbynameindex&lang=en>
>[/color]
I Don't Like Spam
Guest
 
Posts: n/a
#6: Nov 23 '05

re: Accessing a control by name


Jack Russell wrote:[color=blue]
> 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[/color]

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

Chris
Cor Ligthert [MVP]
Guest
 
Posts: n/a
#7: Nov 23 '05

re: Accessing a control by name


Jack,
[color=blue]
> So dim s as string
> s="label1"
> Now I want to say s.text="Hello"
>[/color]
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


Jack Russell
Guest
 
Posts: n/a
#8: Nov 23 '05

re: Accessing a control by name


Cor Ligthert [MVP] wrote:[color=blue]
> Jack,
>
>[color=green]
>>So dim s as string
>>s="label1"
>>Now I want to say s.text="Hello"
>>[/color]
>
> 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
>
>[/color]
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
Cor Ligthert [MVP]
Guest
 
Posts: n/a
#9: Nov 23 '05

re: Accessing a control by name


Jack,
[color=blue]
> 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[/color]


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


Jack Russell
Guest
 
Posts: n/a
#10: Nov 23 '05

re: Accessing a control by name


Cor Ligthert [MVP] wrote:[color=blue]
> Jack,
>
>[color=green]
>>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[/color]
>
>
>
> 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
>
>[/color]
Cor,

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

Jack
Herfried K. Wagner [MVP]
Guest
 
Posts: n/a
#11: Nov 23 '05

re: Accessing a control by name


"Jack Russell" <jackr@norubbish.tpg.com.au> schrieb:[color=blue]
> 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.[/color]

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

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Closed Thread