473,769 Members | 4,831 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using Variables to store a Button's Name and Disable it Using the Variable Value

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.btnMyLittleB utton.Name.ToSt ring

How can I disable this button using the variable value?

I can do this:

Me.btnMyLittleB utton.Enabled = False

However, how can I get the name of the button (stored in TheName
variable ) and use it to disable it?

Is there a way to accomplish this without going through all the
controls in the form?

Don't want something like this:
Dim ctr As Control
For Each ctr In CurrentControl. Controls
If ctr.Name = TheName Then
ctr.Enabled = False
End If
Next

or writing the control names into a hashtable

What I want is something simple as the original example
Me.btnMyLittleB utton.Enabled = False ---TheName.enabled = False

Does anyone has something better?

Thanks!

Apr 16 '07 #1
7 5725
On Apr 16, 3:48 pm, "John Smith" <I...@NETZERO.N ETwrote:
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.btnMyLittleB utton.Name.ToSt ring

How can I disable this button using the variable value?

I can do this:

Me.btnMyLittleB utton.Enabled = False

However, how can I get the name of the button (stored in TheName
variable ) and use it to disable it?

Is there a way to accomplish this without going through all the
controls in the form?

Don't want something like this:
Dim ctr As Control
For Each ctr In CurrentControl. Controls
If ctr.Name = TheName Then
ctr.Enabled = False
End If
Next

or writing the control names into a hashtable

What I want is something simple as the original example
Me.btnMyLittleB utton.Enabled = False ---TheName.enabled = False

Does anyone has something better?

Thanks!

Me.Controls[TheName].Enabled = False

You can access a control in the control collection by it's name in
2005.

--
Tom Shelton

Apr 17 '07 #2
On Apr 16, 9:35 pm, Tom Shelton <tom_shel...@co mcast.netwrote:
On Apr 16, 3:48 pm, "John Smith" <I...@NETZERO.N ETwrote:


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.btnMyLittleB utton.Name.ToSt ring
How can I disable this button using the variable value?
I can do this:
Me.btnMyLittleB utton.Enabled = False
However, how can I get the name of the button (stored in TheName
variable ) and use it to disable it?
Is there a way to accomplish this without going through all the
controls in the form?
Don't want something like this:
Dim ctr As Control
For Each ctr In CurrentControl. Controls
If ctr.Name = TheName Then
ctr.Enabled = False
End If
Next
or writing the control names into a hashtable
What I want is something simple as the original example
Me.btnMyLittleB utton.Enabled = False ---TheName.enabled = False
Does anyone has something better?
Thanks!

Me.Controls[TheName].Enabled = False

You can access a control in the control collection by it's name in
2005.

--
Tom Shelton- Hide quoted text -

- Show quoted text -
Hi Tom, thanks for replying, but I am not using vb.net 2005. I have
VB.NET 2003.

If I use that code, I get the 'Enabled' is not a member of 'string'
error.

Apr 17 '07 #3
On Apr 16, 5:48 pm, "John Smith" <I...@NETZERO.N ETwrote:
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.btnMyLittleB utton.Name.ToSt ring

How can I disable this button using the variable value?

I can do this:

Me.btnMyLittleB utton.Enabled = False

However, how can I get the name of the button (stored in TheName
variable ) and use it to disable it?

Is there a way to accomplish this without going through all the
controls in the form?

Don't want something like this:
Dim ctr As Control
For Each ctr In CurrentControl. Controls
If ctr.Name = TheName Then
ctr.Enabled = False
End If
Next

or writing the control names into a hashtable

What I want is something simple as the original example
Me.btnMyLittleB utton.Enabled = False ---TheName.enabled = False

Does anyone has something better?

Thanks!
Do you have to store the button name into a variable? It would be a
lot easier to just store the button into the variable:

Dim theButton as Button = Me.btnMyLittleB utton

theButton.Enabl ed = False

Thanks,

Seth Rowe

Apr 17 '07 #4
Hi Rowe, thanks for replying.

Well.. I cannot store the button into the variable. I'm supposed to
only know the button name.

I've tried to set the variable as a string, then as an object, but so
far I can't get it right.
I really hope this could be as easy as what Tom suggested:

Me.Controls[TheName].Enabled = False

The problem is that whenever I use the me. part, I get an error saying
that the variable is not a member of my form.

Is there a way to cast the variable as the button name using something
like DirectCast?

Thanks for all your help!

Apr 17 '07 #5
Well.. I cannot store the button into the variable. I'm supposed to
only know the button name.
Is this a school assignment?

I see no other time when you're only "supposed to know" a button name.

Thanks,

Seth Rowe
On Apr 17, 12:44 pm, John Smith <I...@NETZERO.N ETwrote:
Hi Rowe, thanks for replying.

Well.. I cannot store the button into the variable. I'm supposed to
only know the button name.

I've tried to set the variable as a string, then as an object, but so
far I can't get it right.

I really hope this could be as easy as what Tom suggested:

Me.Controls[TheName].Enabled = False

The problem is that whenever I use the me. part, I get an error saying
that the variable is not a member of my form.

Is there a way to cast the variable as the button name using something
like DirectCast?

Thanks for all your help!

Apr 17 '07 #6
On Apr 17, 12:52 pm, rowe_newsgroups <rowe_em...@yah oo.comwrote:
Well.. I cannot store the button into the variable. I'm supposed to
only know the button name.

Is this a school assignment?

I see no other time when you're only "supposed to know" a button name.

Thanks,

Seth Rowe

On Apr 17, 12:44 pm, John Smith <I...@NETZERO.N ETwrote:
Hi Rowe, thanks for replying.
Well.. I cannot store the button into the variable. I'm supposed to
only know the button name.
I've tried to set the variable as a string, then as an object, but so
far I can't get it right.
I really hope this could be as easy as what Tom suggested:
Me.Controls[TheName].Enabled = False
The problem is that whenever I use the me. part, I get an error saying
that the variable is not a member of my form.
Is there a way to cast the variable as the button name using something
like DirectCast?
Thanks for all your help!- Hide quoted text -

- Show quoted text -
:-)

Yes, it is and it's driving me crazy!

Apr 17 '07 #7
On Apr 17, 2:10 pm, John Smith <I...@NETZERO.N ETwrote:
On Apr 17, 12:52 pm, rowe_newsgroups <rowe_em...@yah oo.comwrote:
Well.. I cannot store the button into the variable. I'm supposed to
only know the button name.
Is this a school assignment?
I see no other time when you're only "supposed to know" a button name.
Thanks,
Seth Rowe
On Apr 17, 12:44 pm, John Smith <I...@NETZERO.N ETwrote:
Hi Rowe, thanks for replying.
Well.. I cannot store the button into the variable. I'm supposed to
only know the button name.
I've tried to set the variable as a string, then as an object, but so
far I can't get it right.
I really hope this could be as easy as what Tom suggested:
Me.Controls[TheName].Enabled = False
The problem is that whenever I use the me. part, I get an error saying
that the variable is not a member of my form.
Is there a way to cast the variable as the button name using something
like DirectCast?
Thanks for all your help!- Hide quoted text -
- Show quoted text -

:-)

Yes, it is and it's driving me crazy!
Why can't you loop through the control collection or use a hash table?

In the future you should ask your professor/teacher or a fellow
student for help - this newsgroup is not here to do your homework!

Thanks,

Seth Rowe

Apr 17 '07 #8

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

Similar topics

7
5657
by: Gary | last post by:
I haver a table of students - Say 100 students that I need to be able to update/delete and amend. I know I can do this one student at a time which is simple but lets say I want to see all the students on the screen at the same time, modify some, mark some for deletion and even have blank fields at the end to add a new record. In HTML which is generated I label each row and input field with a name/number combination i.e <input type=text...
0
3940
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen. It is almost like it is trying to implement it's own COM interfaces... below is the header, and a link to the dll+code: Zip file with header, example, and DLL:...
1
6428
by: ratnakarp | last post by:
Hi, I have a search text box. The user enters the value in the text box and click on enter button. In code behind on button click i'm writing the code to get the values from the database and binding it to a repeater control. This repeater control has multiple text boxes and buttons. Can you please tell me how can i do paging in this case ? I'm posting my code below. The problem is that if i click on "AdjustThisAd" button, it opens...
2
5047
by: John Regan | last post by:
Hello All I am trying to find the owner of a file or folder on our network (Windows 2000 Server) using VB.Net and/or API. so I can search for Folders that don't follow our company's specified folder structure and naming conventions and then send a Net send message to those users telling them to rectify. The information I want to get is when you select the file/folder and then: Properties -> Security Tab -> Advanced Button -> Owner Tab ->...
3
1800
by: Brett Wesoloski | last post by:
I can not seem to figure this out, but really haven't work a lot with javascrip and .NET. I have a data grid and I want to put a button in it and when the button is pressed it will call my javascript. Now the grid is in a .ascx file. The other kicker is I want to also use the databinder property to get a value as the grid is loading and use that in my java script. Here is what I have so far as for getting the javascript to do what I...
21
34437
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most obvious of which is the sharing of files. For example, you upload images to a server to share them with other people over the Internet. Perl comes ready equipped for uploading files via the CGI.pm module, which has long been a core module and allows users...
2
3173
by: shivendravikramsingh | last post by:
hi friends, i m using a ajax function for retrieving some values from a database table,and display the values in required field,my prob is that the ajax function i m using is working f9 once,but if i change something in php file using in ajax function.it not refreshed,means its shows the previous result it not get updated.i can't understand whats the prob.this is the code i m using: <? include("config.inc.php"); //error_reporting(0); ...
5
2958
by: coflo | last post by:
I am relatively new to XSL transforms so I apologize if my language or verbage is incorrect. I am trying to invoke a JS function of a flash player which requires a URI. In order to do this I would like to take the RSS feed, the snippet below, and grab the uri from the <enclosure> tag. You will see that there is a &uri=channels/39174/186941 inside of the url="" i would like to grab this piece and insert it into my XSL <a href= as currently...
10
9113
by: sowmyati | last post by:
HI All, I am new to javascript. I have snippet wherein i am giving a brief note on what i am trying to do. In the below have a variable by name stuff. trying to reset the page. Part of the code which does reset is attached below. there is a reset button which will reset the connection and it takes two min for data loading during which the reset button has to be disabled and later after two mins it should enable the button for the user. ...
0
9579
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
10199
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
9849
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
8861
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
7393
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
6661
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5293
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5433
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2810
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.