473,769 Members | 5,131 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using Variable Control Name

I'm capturing the checked radio button to XML file using the name of the
radio button. I want to read my xml file to find which button was checked
on close and the check the appropriate button when for loads. How do I use
a variable control name. This is what I'm trying to do below but of course
it doesn't work, I'm rookie.

Thanks
Dim rbchecked as String
'rbchecked is name of radio button checked on exit from XML

rbchecked.check ed = true

Nov 20 '05 #1
3 3848
Hi,

This will check every control on the form. If the control is a
radiobutton it will write its name and if it is checked to the output
window.

RadioButtonChec ked(Me.Controls )

Private Sub RadioButtonChec ked(ByVal sender As
Control.Control Collection)
For Each ctrl As Control In sender
If TypeOf ctrl Is RadioButton Then
Debug.WriteLine (String.Format( "{0} Checked {1}",
ctrl.Name, DirectCast(ctrl , RadioButton).Ch ecked))
End If
RadioButtonChec ked(ctrl.Contro ls)
Next
End Sub

Ken
-----------------------

"B-Dog" <bd***@hotmail. com> wrote in message
news:Ob******** ******@TK2MSFTN GP12.phx.gbl:
I'm capturing the checked radio button to XML file using the name of the

radio button. I want to read my xml file to find which button was checked

on close and the check the appropriate button when for loads. How do I
use
a variable control name. This is what I'm trying to do below but of
course
it doesn't work, I'm rookie.

Thanks
Dim rbchecked as String
'rbchecked is name of radio button checked on exit from XML

rbchecked.check ed = true


--
Outgoing mail is certified Virus Free.
Checked by AVG Anti-Virus (http://www.grisoft.com).
Version: 7.0.230 / Virus Database: 263.0.0 - Release Date: 6/2/2004
Nov 20 '05 #2
* "B-Dog" <bd***@hotmail. com> scripsit:
I'm capturing the checked radio button to XML file using the name of the
radio button. I want to read my xml file to find which button was checked
on close and the check the appropriate button when for loads. How do I use
a variable control name.


My FAQ:

\\\
Private Function FindControl( _
ByVal ControlName As String, _
ByVal CurrentControl As Control _
) As Control
Dim ctr As Control
For Each ctr In CurrentControl. Controls
If ctr.Name = ControlName Then
Return ctr
Else
ctr = FindControl(Con trolName, ctr)
If Not ctr Is Nothing Then
Return ctr
End If
End If
Next ctr
End Function
///

Usage:

\\\
DirectCast(Find Control("btnBla ", Me), Button).Enabled = False
///

Notice that the procedure listed above is "slow", if you have to access a
lot of controls by name very often, you should store references to them in a
'Hashtable' object. You can use the name of the control as key:

\\\
Private m_Controls As New Hashtable()
///

Adding a control:

\\\
Dim DynamicPictureB ox As New PictureBox()
DynamicPictureB ox.Name = "PictureBox 1"
m_Controls.Add( DynamicPictureB ox.Name, DynamicPictureB ox)
///

Looking for a control:

\\\
Dim p As PictureBox = DirectCast(m_Co ntrols.Item("Pi ctureBox1"), PictureBox)
///

Removing a control:

\\\
m_Controls.Remo ve("PictureBox1 ")
///

Sometimes it's even better to add the control to an array. This will allow
fast and easy index-based access to the control references:

\\\
Dim MyLabels() As Label = {Label1, Label2, ..., Label10}
///

Access by 'MyLabels(0)' to 'MyLabels(9)'.

Control arrays:

Control arrays, as known from VB6, are not included in VB.NET 2002/2003.

Creating Control Arrays in Visual Basic .NET and Visual C# .NET:
<URL:http://msdn.microsoft. com/library/en-us/dv_vstechart/html/vbtchCreatingCo ntrolArraysInVi sualBasicNETVis ualCNET.asp>

WinForms Controls--Creating Control Arrays in VB.NET
<URL:http://www.devx.com/vb2themax/Article/19907/>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #3
Wow, thanks for the reply, looks more complicated than I thought it would
be, to get around it before I had used and Case, If string = "" then
radio.checked = true etc. which was only a few lines. May stick with that
since I only have a few radio buttons. Thanks!

"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:2i******** ****@uni-berlin.de...
* "B-Dog" <bd***@hotmail. com> scripsit:
I'm capturing the checked radio button to XML file using the name of the
radio button. I want to read my xml file to find which button was checked on close and the check the appropriate button when for loads. How do I use a variable control name.
My FAQ:

\\\
Private Function FindControl( _
ByVal ControlName As String, _
ByVal CurrentControl As Control _
) As Control
Dim ctr As Control
For Each ctr In CurrentControl. Controls
If ctr.Name = ControlName Then
Return ctr
Else
ctr = FindControl(Con trolName, ctr)
If Not ctr Is Nothing Then
Return ctr
End If
End If
Next ctr
End Function
///

Usage:

\\\
DirectCast(Find Control("btnBla ", Me), Button).Enabled = False
///

Notice that the procedure listed above is "slow", if you have to access a
lot of controls by name very often, you should store references to them in

a 'Hashtable' object. You can use the name of the control as key:

\\\
Private m_Controls As New Hashtable()
///

Adding a control:

\\\
Dim DynamicPictureB ox As New PictureBox()
DynamicPictureB ox.Name = "PictureBox 1"
m_Controls.Add( DynamicPictureB ox.Name, DynamicPictureB ox)
///

Looking for a control:

\\\
Dim p As PictureBox = DirectCast(m_Co ntrols.Item("Pi ctureBox1"), PictureBox) ///

Removing a control:

\\\
m_Controls.Remo ve("PictureBox1 ")
///

Sometimes it's even better to add the control to an array. This will allow fast and easy index-based access to the control references:

\\\
Dim MyLabels() As Label = {Label1, Label2, ..., Label10}
///

Access by 'MyLabels(0)' to 'MyLabels(9)'.

Control arrays:

Control arrays, as known from VB6, are not included in VB.NET 2002/2003.

Creating Control Arrays in Visual Basic .NET and Visual C# .NET:
<URL:http://msdn.microsoft.com/library/en.../vbtchCreating
ControlArraysIn VisualBasicNETV isualCNET.asp>
WinForms Controls--Creating Control Arrays in VB.NET
<URL:http://www.devx.com/vb2themax/Article/19907/>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #4

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

Similar topics

17
4227
by: Danny J. Lesandrini | last post by:
The following code works with a standard MDB to navigate to a particluar record (with a DAO recordset, of course) but it's giving me problems in an ADP I'm working on. Dim rs As ADODB.Recordset Set rs = Me.RecordsetClone rs.Find "=" & lngContractID If Not rs.EOF Then Me.Bookmark = rs.Bookmark I must site the Heisenberb Uncertainty Principal here, as it
1
4010
by: Daveyk0 | last post by:
Hello there, I have a front end database that I have recently made very many changes to to allow off-line use. I keep copies of the databases on my hard drive and link to them rather than the live databases on the network. Is there a way, via code, when I get back in-house from being on the road to click a button, and select the backends I want to link to? I would want to delete all the current links and link to the "live"
5
3161
by: Marcel Gelijk | last post by:
Hi, I am trying to create a User Control that is located in a seperate class library. The User Control contains a textbox and a button. The page generates an exception when it tries to access the code variable that are supposed to be linked to the contained controls. It runs fines when everything is contained in a single web form project. What do I need to do to make it work from a class library?
2
1155
by: DocAccolade | last post by:
I am trying to include a legacy com control (controlname.ocx) in an asp.net application using vs 2003. I have added the control to the user control tool box, then dragged it to the form. However, when i try to reference it in code, it does not seem to exist. I declared the object variable and the ide reports the class members. The intellisense then recognizes the child members of the object variable and provides them in a drop down,...
15
2419
by: Joe Fallon | last post by:
I would like to know how you can figure out how much memory a given instance of a class is using. For example, if I load a collection class with 10 items it might use 1KB, and if I load it with 1000 items it might use 100KB. How do I measure the amount of memory used once the class is loaded? Thanks! -- Joe Fallon
9
2191
by: KenLee | last post by:
I made an application which includes classic asp page and asp.net page. when I tried to redirect from classic asp page to asp.net 2.0 page, it works under my local IIS directory. ex) <a href="default.aspx?store=<%=rs("store")%>"><%=rs("store")%></a> However, When I copy that application into one of IIS directory in another intranet server, it doesn't work.
5
1836
by: glenn | last post by:
Hi folks, The problem I have is that a query string works if hard-coded but if I pass a variable to it, it does not work as shown here. This works: querystring="SELECT * FROM USERS WHERE CNAME = 'MICROSOFT'" This does not work: Dim var as string
7
5726
by: John Smith | last post by:
Hello, I have a simple question, I have a vb.net form with several buttons. If I store the name of a button in a variable.. Dim TheName as string TheName = Me.btnMyLittleButton.Name.ToString How can I disable this button using the variable value?
7
2889
by: bryant | last post by:
Hi all. I am new to ASP and working in Expression Web. The following query displays the information I need in the gridview for a single record. SELECT "OE_HDR"."ORD_NO", "OE_HDR"."CUST_NAM", "OE_HDR"."SLS_MAN_NO", "OE_HDR"."SLS_MAN_INITIALS", "OE_HDR"."ORD_DAT", "OE_HDR"."SHIP_DAT" FROM "OE_HDR" WHERE ("OE_HDR"."ORD_NO"='174310') I also have DropDownList1 working properly. For the WHERE portion of
0
9583
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10210
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10039
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9990
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9860
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8869
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7406
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5445
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3560
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.