473,503 Members | 722 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Enable checkboxes based on textbox value

7 New Member
I have a form with a lot of text boxes and an equal number of check boxes. I want the check box to be disabled if the text in the text box is a certain value. I'm still a VB noob, so forgive me if my question is too trivial.


Obviously this doesn't work, otherwise I wouldn't be asking, but by looking at this you should be able to see what I am trying to do. Does anyone have a solution or suggestion?

Expand|Select|Wrap|Line Numbers
  1.         Dim x
  2.         Dim y As New Control
  3.         Dim z As New Control
  4.  
  5.         For x = 1 To 40
  6.             y = "txtTextBox" & x
  7.             z = "chkcheckBox" & x
  8.             If y.Text = "3" Then
  9.                 z.Enabled = False
  10.             End If
  11.         Next
The error is....
Unable to cast object of type 'System.String' to type System.Windows.Forms.Control'.

Now I know I can't refer to a control using the string combination, but thats all I could think of to get through all of my controls in a for..next.


Thanks
Apr 25 '07 #1
1 2005
Killer42
8,435 Recognized Expert Expert
I'm not familiar with VB.Net since I use the older VB6, but I can suggest something to try..
Expand|Select|Wrap|Line Numbers
  1.         Dim x
  2.         Dim y As New Control
  3.         Dim z As New Control
  4.  
  5.         For x = 1 To 40
  6.             ' y = "txtTextBox" & x
  7.             Set y = Me.Controls("txtTextBox" & Format(x))
  8.             ' z = "chkcheckBox" & x
  9.             Set z = Me.Controls("chkcheckBox" & Format(x))
  10.             If y.Text = "3" Then
  11.                 z.Enabled = False
  12.             End If
  13.         Next
Note that I'm using the Format() function to strip off the extra space that you get when appending a number to a string. This applies in VB6, but may not in your version. Feel free to experiment. :)
Apr 25 '07 #2

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

Similar topics

2
9723
by: HolaGoogle | last post by:
Hi all, Can you please tell me what's wrong with my code??? i do have this database in wich i have to field.One is a "yes/no" field and another one is "number" field. To display the yes/no field...
2
6416
by: HolaGoogle | last post by:
Can you please tell me the right way to do this?? it's realy important! thanks in advance... Hi all, Can you please tell me what's wrong with my code??? i do have this database in wich i have...
9
2954
by: Gary | last post by:
Hello, Is it possible to dynamically update a textbox with words chosen from a list using form checkboxes and javascript? Gary
1
4223
by: hortoristic | last post by:
We are using JavaScript to Enable/Disable certain fields on web pages based on business rules. A simple example is if when using an option type tag, and the two options are Yes and No. If YES...
3
3783
by: DBQueen | last post by:
I have a form with lines of controls. On some of the lines there are 3 controls (call them A,B,C); other lines have only control A. The controls have been numbered sequentially (Q20, Q21....Q76)...
9
4930
by: Susan Bricker | last post by:
Hi. I have two questions ... (1) I want to use a Listbox to enable the user to select 1 or many items from the list. However, I'm having trouble figuring out how to find out t which items have...
9
4359
by: Marc | last post by:
Okay, here's the problem - I have 3 radio buttons, and 11 check boxes (which are disabled by default). I have the javascript below which when the last radio button is clicked, enables the...
3
2582
sunbin
by: sunbin | last post by:
Hi, I am having in a Trouble when working with dynamic checkboxes (i.e. checkboxes with the same name, e.g. <input type="checkbox" name = "check" value="dynamic integer value">) I have...
5
11805
by: andersond | last post by:
I need to enable or disable a submit button based on the value of a data field stored in a database. I have found working examples of how to enable or disable based on a checkbox; but, I need it to...
0
7203
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,...
0
7089
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
7463
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
5581
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,...
1
5017
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...
0
4678
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
3168
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...
0
3157
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1515
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.