473,657 Members | 2,266 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 2011
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
9732
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 in my asp form i use a checkbox and fot he other field i use a normal text box. if the yes/no field is checked then the other field is enabled otherwise it has to be disabled.Here's what i've done so far: Do While Not ObjRS.EOF <td><input...
2
6452
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 to field.One is a "yes/no" field and another one is "number" field. To display the yes/no field in my asp form i use a checkbox and fot he other field i use a normal text box. if the yes/no field is checked then the other field is enabled...
9
2967
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
4243
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 is selected - enable a field to use the M$ Datepicker. Using the code below works for most of our fields, however the problem is that when the field is re-enabled - it remembers the original date or data prior to it being disabled - despite the...
3
3793
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) and they were put onto the form in the numerical sequence. I have given the A's with B & C's on the same line a tag=1; B.tag=2, C,tag=2) I am trying to write 2 modules so that the following occurs (on Form_Current and 'A' Control_Before or...
9
4940
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 been selected. How can I do that? Given the listindex, .selected, .itemsselected, .itemdata properties -- I'm getting confused. (2) I, actually, have two listboxes on the form and I want to ONLY let the user select items in one list. The...
9
4370
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 checkboxes. <script type="text/javascript"> //<!]> </script> I used the JavaScript on 2 pages, on almost identical forms, and for some reason it doesn't work on the 2nd one - they just stay disabled,
3
2597
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 submitted an HTML form (which contains dynamic textboxes and dynamic checkboxes with a Post Button(input type="button")) by using Ajax function. (onClick="return ajaxFunction(document.getElementById('formid'));") In the ajax function, i have collected...
5
11817
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 work based on a data field value. I have created a textbox in a hidden area that contains the stored data value. I have set the beginning value of the submit button to disabled. I want the submit button to be enabled if the value in the textbox is...
0
8837
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
8739
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
8512
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
8612
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...
1
6175
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
5638
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
4171
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
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1732
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.