Newbi here,
How do I find a specific form control without using a For Each loop? While the loop works to find a control, it seems to have overhead I'm trying to avoid. I'm using A2K.
Here's the code I'm trying to avoid. There must be another way to find a control. - Dim ctl as Control
-
For each ctl in Me
-
do this and that
-
Next ctl
Thanks in advance,
=Paul
7 15128
I'm afraid, Paul, that you're going to have to give a better explanation of what you're trying to do in order for us to help you. The code you've cited is generally used to find a group of controls of the same type in order to carry out some action rather than to find a specific control.
Welcome to TheScripts!
Linq ;0)> ADezii 8,834
Recognized Expert Expert
Newbi here,
How do I find a specific form control without using a For Each loop? While the loop works to find a control, it seems to have overhead I'm trying to avoid. I'm using A2K.
Here's the code I'm trying to avoid. There must be another way to find a control.
Dim ctl as Control
For each ctl in Me
do this and that
Next ctl
Thanks in advance,
=Paul
Your other option is a For ...Next construct, but I'm not so sure that you will gain any benefits by using it: -
Dim intNoOfControls As Integer, intCounter As Integer
-
-
intNoOfControls = Me.Controls.Count
-
-
For intCounter = 0 To intNoOfControls - 1
-
Debug.Print Me.Controls(intCounter).Name
-
Next
I'm afraid, Paul, that you're going to have to give a better explanation of what you're trying to do in order for us to help you. The code you've cited is generally used to find a group of controls of the same type in order to carry out some action rather than to find a specific control.
Welcome to TheScripts!
Linq ;0)>
To be more specific .... I want to change the value in a Label's caption property when a scenario occurs to the attached 'Text Box' control. How can I do this without using a "For Each Loop" to find the label control? There is an obvious link between Label and Text Box controls (the two are created together). But, how to take advantage of the link in code is escaping me.
=Paul
ADezii 8,834
Recognized Expert Expert
To be more specific .... I want to change the value in a Label's caption property when a scenario occurs to the attached 'Text Box' control. How can I do this without using a "For Each Loop" to find the label control? There is an obvious link between Label and Text Box controls (the two are created together). But, how to take advantage of the link in code is escaping me.
=Paul
There is a Linkage as you surmise and it is a Parent/Child Linkage. The Parent Property of a Label Control returns the Control the Label is Linked to. A simple example will illustrate this point. Assume you have a Last Name Text Box on a Form called txtLastName, and its associated Label is named lblLastName: -
Debug.Print Me![lblLastName].Parent 'returns the Value in txtLastName Field
-
Debug.Print Me![lblLastName].Parent.Name 'returns the Name of the associated Text Box
-
'Control, namely txtLastName
-
aaahhhh ..... very close. But, I notice that 'Parent' is valid option after the control, but 'Child' is not. Does this mean it's a one way link and I cannot go from 'Text Box' to 'Label' control?
=Paul
ADezii 8,834
Recognized Expert Expert
aaahhhh ..... very close. But, I notice that 'Parent' is valid option after the control, but 'Child' is not. Does this mean it's a one way link and I cannot go from 'Text Box' to 'Label' control?
=Paul
To the best of my knowledge, it is a one way Link as you so indicate. There is no associated Child Property for the Parent.
NeoPa 32,556
Recognized Expert Moderator MVP
Look in the Controls item of the control you're interested in. There should only be the one (#0) for simple controls associated with a label.
I tried it with a ComboBox called cboResults. The associated label is called Label3. - Debug.Print "Combo - " & Me.cboResults.Controls(0).Name
-
Debug.Print "Label - " & Me.Label3.Parent.Name
produced : - Combo - Label3
-
Label - cboResults
Sign in to post your reply or Sign up for a free account.
Similar topics
by: patrick_a |
last post by:
Hello,
I am trying to insert multiple instances of a custom user control into a
placeholder on an aspx page, based on the records retrieved from the
database. I use the datareader to loop through...
|
by: TomislaW |
last post by:
How to find all user controls (ascx) loaded on a Page?
|
by: PCH |
last post by:
I have an c# asp.net (.net 1.1) web page, viewstate on.
The problem I am having is on the button click postback to update.
Heres the situation:
I have an asp table that has 1 header row.
...
|
by: Sacha Korell |
last post by:
I'm trying to load a drop-down list with all DropDownList control names from
another page.
How would I be able to find those DropDownList controls? The FindControl
method will only find a...
|
by: Nick Stansbury |
last post by:
Hi,
I have a loop running on Page_PreRender that sets a number of controls
to invisible based on a set of criteria. Before I do this however, I set all
of the drop down lists to be visible with...
|
by: Ian |
last post by:
Hi
I can access a particular control on a form by it's index e.g. me.Controls.Item(0).Name
How would I access the control by name e.g. me.Controls.Item("Label1").Name. Is it possible?
...
|
by: Dennis D. |
last post by:
Hello:
There are a series of textboxes (x.text, y.text, z.text etc.) in which user input is expected.
As:
dtmX=CDate(x.text)
dtmY=CDate(y.text)
dtmZ=CDate(z.text)
where x, y, and z.text...
|
by: ma740988 |
last post by:
Trying to get more acclimated with the use of function objects. As
part of my test, consider:
# include <vector>
# include <iostream>
# include <algorithm>
#include <stdexcept>
#include...
|
by: Sudharsan |
last post by:
Hi
I have developed a Windows Control Library in VC.NET
The component will play back video files and this component is used in C#
applications to display multiple videos simultaneously.
The...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
|
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...
|
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,...
|
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: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |