473,373 Members | 1,611 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,373 software developers and data experts.

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.btnMyLittleButton.Name.ToString

How can I disable this button using the variable value?

I can do this:

Me.btnMyLittleButton.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.btnMyLittleButton.Enabled = False ---TheName.enabled = False

Does anyone has something better?

Thanks!

Apr 16 '07 #1
7 5681
On Apr 16, 3:48 pm, "John Smith" <I...@NETZERO.NETwrote:
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?

I can do this:

Me.btnMyLittleButton.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.btnMyLittleButton.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...@comcast.netwrote:
On Apr 16, 3:48 pm, "John Smith" <I...@NETZERO.NETwrote:


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?
I can do this:
Me.btnMyLittleButton.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.btnMyLittleButton.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.NETwrote:
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?

I can do this:

Me.btnMyLittleButton.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.btnMyLittleButton.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.btnMyLittleButton

theButton.Enabled = 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.NETwrote:
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...@yahoo.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.NETwrote:
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.NETwrote:
On Apr 17, 12:52 pm, rowe_newsgroups <rowe_em...@yahoo.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.NETwrote:
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
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...
0
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....
1
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...
2
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...
3
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...
21
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...
2
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...
5
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...
10
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.