PC Review


Reply
Thread Tools Rate Thread

Accessing a control by name

 
 
Jack Russell
Guest
Posts: n/a
 
      7th Nov 2005
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
 
Reply With Quote
 
 
 
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      7th Nov 2005
"Jack Russell" <(E-Mail Removed)> schrieb:
> 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?


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/>
 
Reply With Quote
 
 
 
 
=?Utf-8?B?dnZlbms=?=
Guest
Posts: n/a
 
      7th Nov 2005
Jack:

Absolutely!

myTextBox.Text = "I changed the text value"

will do just that!

Am I missing something?

"Jack Russell" wrote:

> 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
>

 
Reply With Quote
 
Jack Russell
Guest
Posts: n/a
 
      7th Nov 2005
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:
> Jack:
>
> Absolutely!
>
> myTextBox.Text = "I changed the text value"
>
> will do just that!
>
> Am I missing something?
>
> "Jack Russell" wrote:
>
>
>>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
>>

S
 
Reply With Quote
 
Jack Russell
Guest
Posts: n/a
 
      7th Nov 2005
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:

> "Jack Russell" <(E-Mail Removed)> schrieb:
>
>> 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?

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

 
Reply With Quote
 
I Don't Like Spam
Guest
Posts: n/a
 
      7th Nov 2005
Jack Russell wrote:
> 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
 
Reply With Quote
 
Cor Ligthert [MVP]
Guest
Posts: n/a
 
      7th Nov 2005
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


 
Reply With Quote
 
Jack Russell
Guest
Posts: n/a
 
      7th Nov 2005
Cor Ligthert [MVP] wrote:
> 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,

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
 
Reply With Quote
 
Cor Ligthert [MVP]
Guest
Posts: n/a
 
      7th Nov 2005
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


 
Reply With Quote
 
Jack Russell
Guest
Posts: n/a
 
      7th Nov 2005
Cor Ligthert [MVP] wrote:
> 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,

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

Jack
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: creating last name first, first name last from a column of first name last name data Rick Rothstein Microsoft Excel Programming 0 27th Jul 2009 07:25 AM
1st name last name to last name, 1st name shan Microsoft Excel Worksheet Functions 2 11th Mar 2009 07:59 PM
change first name last name to last name first name Doris smith Microsoft Excel Misc 3 25th Feb 2009 12:35 PM
how do I reveerse name order last name, first name to first name, last name Don Smith Microsoft Excel Discussion 9 29th Nov 2006 10:55 PM
Changing a list from last name, first name to first name, last name zgall1 Microsoft Excel Misc 3 17th Feb 2006 12:49 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:21 PM.