473,387 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Access object through String ?

Hi,

Say, I have 20 textboxes on my form placed in different panels, groupboxes.
The names of the textboxes range from "TextBox1" to "TextBox20".

I want to get a reference to each textbox using it's already known name, as
in :
-------------------------------------------------------
Dim i As Integer
For i = 1 To 20
Dim txt As TextBox = CType("Textbox" & i, TextBox)
^^^^^^^^^^
txt.Text = "Number " & i
Next
-------------------------------------------------------
But of course, the above code doesn't even compile, since a String cannot be
converted to a System.Windows.Forms.TextBox. Of course, I could use other
options(Such as For-each loops), but my main purpose is not that. (See
below)

So, my question actually is: How do I use a dynamically constructed string,
containing the name of an Object (or Control) to get a reference to the
Object itself ?

Regards,

Cerebrus.

Feb 20 '06 #1
2 1014
Oh Never mind !

I see someone asked the very same question at this very same time and
already got a reply !

http://groups.google.com/group/micro...2b99dd65a427d1

Some coincidence !

:-)

Cerbrus.

Feb 20 '06 #2
"Cerebrus99" <zo*****@sify.com> schrieb:
Say, I have 20 textboxes on my form placed in different panels,
groupboxes.
The names of the textboxes range from "TextBox1" to "TextBox20".

I want to get a reference to each textbox using it's already known name,
as
in :
[...]
Dim txt As TextBox = CType("Textbox" & i, TextBox)


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

Feb 20 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Nicola | last post by:
Hi Everyone, I am new to programming and would like to know how to open an access Report from within vb 6. I am trying to write a program to organise cross stitch threads. I have found out how...
7
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I...
11
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
2
by: Brent Burkart | last post by:
I am trying to send an email using SMTP server through IIS. I am recieving the following error. Access is denied. Description: An unhandled exception occurred during the execution of the...
2
by: Dean Slindee | last post by:
Anybody written code in VB.NET to: 1) show a print preview window of reports already written and stored in an Access 2002 database; or 2) execute the print of a report stored in an Access 2002...
6
by: moondaddy | last post by:
I'm new to c# and am wondering if its possible to access members of a nested class. Can someone please advise? Thanks. class Program { static void Main(string args) { try { Test1 obj =...
9
by: Wayne Smith | last post by:
I've come up against a major headache that I can't seem to find a solution for but I'm sure there must be a workaround and I would really be grateful of any help. I'm currently building a web...
2
by: job | last post by:
In a sharepoint setup using smartpart to load our user controls using enterprise blocks (data) we are getting some strange errors (logged to the event log). We dont get the error all the time. When...
7
by: Andy B | last post by:
I have a class I am creating for data access. I need to access controls from inside the class that are on a particular page. How do I do this? or is creating an instance of the page class and using...
2
by: fgh.vbn.rty | last post by:
Hi, I'm not sure if i'm asking the question correctly but anyway here it is. Say I have 3 classes - class A, class B, class R. 1) A and B are the building blocks and R is like a repository...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.