473,466 Members | 1,286 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Find Control without For each loop

3 New Member
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.
Expand|Select|Wrap|Line Numbers
  1. Dim ctl as Control
  2. For each ctl in Me
  3.   do this and that
  4. Next ctl
Thanks in advance,
=Paul
Nov 10 '07 #1
7 15128
missinglinq
3,532 Recognized Expert Specialist
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)>
Nov 10 '07 #2
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:
Expand|Select|Wrap|Line Numbers
  1. Dim intNoOfControls As Integer, intCounter As Integer
  2.  
  3. intNoOfControls = Me.Controls.Count
  4.  
  5. For intCounter = 0 To intNoOfControls - 1
  6.   Debug.Print Me.Controls(intCounter).Name
  7. Next
Nov 10 '07 #3
morrisp
3 New Member
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
Nov 10 '07 #4
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:
Expand|Select|Wrap|Line Numbers
  1. Debug.Print Me![lblLastName].Parent          'returns the Value in txtLastName Field
  2. Debug.Print Me![lblLastName].Parent.Name     'returns the Name of the associated Text Box
  3.                                              'Control, namely txtLastName
  4.  
Nov 10 '07 #5
morrisp
3 New Member
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
Nov 11 '07 #6
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.
Nov 11 '07 #7
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.
Expand|Select|Wrap|Line Numbers
  1. Debug.Print "Combo - " & Me.cboResults.Controls(0).Name
  2. Debug.Print "Label - " & Me.Label3.Parent.Name
produced :
Expand|Select|Wrap|Line Numbers
  1. Combo - Label3
  2. Label - cboResults
Nov 13 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

4
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...
6
by: TomislaW | last post by:
How to find all user controls (ascx) loaded on a Page?
5
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. ...
10
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...
6
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...
20
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? ...
10
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...
18
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...
5
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...
1
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...
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
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...
0
tracyyun
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...
0
agi2029
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,...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.