Manipulating object names
Manipulating object names
Manipulating object names
Manipulating object names
Manipulating object names
Manipulating object names Manipulating object names Manipulating object names Manipulating object names Manipulating object names Manipulating object names Manipulating object names Manipulating object names
Manipulating object names Manipulating object names
Manipulating object names
Go Back  Xtreme Visual Basic Talk > > > Manipulating object names


Reply
 
Thread Tools Display Modes
  #1  
Old 12-04-2005, 11:25 AM
0101 0101 is offline
Newcomer
 
Join Date: Dec 2005
Posts: 3
Question Manipulating object names


I am trying to manipulate the naming of objects in my application.

For instance, let's declare and initialize a variable:

Code:
Dim someVariable As String = “Box”

Also imagine that I have two objects in my application: a text box named txtTextBox1 and a button whose name isn't important.

When I press this button I would like to show something else inside the txtTextBox1 textbox. Normally you would do this as such:

Code:
Me.txtTextBox1.Text = “Some text in my textbox”

Now, here is the problem I am having: Instead of typing in “Me.txtTextBox1.Text” I would like to have the name of that textbox called from my variable that I've declared at the beginning.

So essentially what I am trying to do is this (although the below code is not accepted by VB):

Code:
Me.txtText + someVariable + 1.Text = “Some text in my textbox”

In other words, instead of telling the name of the textbox straight up I am creating a variable which will call on whichever textbox that is necessary at the time.

If this is possible to do please let me know by replying below as it will save me a lot of time in trying to do hundreds of loops in an application.

Thank you in advance!
Reply With Quote
  #2  
Old 12-04-2005, 11:58 AM
mrjeffy321 mrjeffy321 is offline
Ultimate Contributor
 
Join Date: Apr 2003
Location: Texas, USA
Posts: 1,623
Default

You can’t do it quite the way you are trying now, but there may be an alternative.
when and where is your "SomeVariable" string being declared? and how are you determining its value?
Instead of declaring a string with a textbox name, why not declare a text box and then set it to reference the text box you want to change.
For example,
Code:
Dim t As TextBox t = TextBox1 t.Text = "new text"
Or how about using a control array of text boxes and identifying them with index numbers?
Reply With Quote
  #3  
Old 12-04-2005, 12:19 PM
0101 0101 is offline
Newcomer
 
Join Date: Dec 2005
Posts: 3
Default

For the project that I am currently making, your way would work but again I would be forced to dynamically generate the name of the textbox.

So, is there any way of dynamically generating the name of the textbox depending on what the user does in an application?

This is actually quite easy to do in PHP, but unfortunately I have not worked with Visual Basic for long enough to know how to apply this from PHP to VB.

Any help?
Reply With Quote
  #4  
Old 12-04-2005, 12:50 PM
mrjeffy321 mrjeffy321 is offline
Ultimate Contributor
 
Join Date: Apr 2003
Location: Texas, USA
Posts: 1,623
Default

Can you give an example of what the user would do in your program that you would then need to generate the name of the textbox?
Reply With Quote
  #5  
Old 12-04-2005, 01:56 PM
herilane's Avatar
herilaneManipulating object names herilane is offline
Unashamed geek

Retired Moderator
* Expert *
 
Join Date: Jul 2003
Location: London, England
Posts: 8,988
Default

You can refer to controls by name using the Me.Controls("controlname") syntax.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Manipulating object names
Manipulating object names
Manipulating object names Manipulating object names
Manipulating object names
Manipulating object names
Manipulating object names Manipulating object names Manipulating object names Manipulating object names Manipulating object names Manipulating object names Manipulating object names
Manipulating object names
Manipulating object names
 
Manipulating object names
Manipulating object names
 
-->