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

Looping through TextBoxes, need help

I want to loop through all my text boxes in my form and write a 0 (zero) in all those which don't have positive integers in them. Don't want any characters or negative numbers, only positive integers.

Thanks in advance
Mar 15 '08 #1
7 1183
janders468
112 Expert 100+
I believe this will do what you want:
Expand|Select|Wrap|Line Numbers
  1.   Dim ctrl As Control
  2.     For Each ctrl In Me.Controls
  3.         If TypeName(ctrl) = "TextBox" Then
  4.             If (Not (IsNumeric(ctrl.Value)) Or (ctrl.Value < 0)) Then
  5.                 ctrl.Value = 0
  6.             End If
  7.         End If
  8.     Next ctrl
  9.  
If you are controlling this from another form then use that form instead of 'me' as the form containing the controls.
Mar 15 '08 #2
Thank you very much! I will try it right away! =)
Mar 15 '08 #3
It say's:

Value is not a member of "system.windows.form.control"

... why?
Mar 15 '08 #4
janders468
112 Expert 100+
Sorry, didn't realize that you were using vb.net, thought it was vb/vba use text instead of value. I just tested this and be sure that when you check for the typename that it is "TextBox" (case is significant) let me know if that works.
Mar 15 '08 #5
Now it works for the negative ingers, but still not if I type a char,

An unhandled exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll

Additional information: Conversion from string "characters" to type 'Double' is not valid.

and it highlights this:

If (Not (IsNumeric(ctrl.Text)) Or (ctrl.Text < 0)) Then

I wrote "characters" in the TextBox...
Mar 15 '08 #6
janders468
112 Expert 100+
Okay Sorry for all the runaround I think this will work for you
Expand|Select|Wrap|Line Numbers
  1.        Dim ctrl As Control
  2.         For Each ctrl In Me.Controls
  3.             If TypeName(ctrl) = "TextBox" Then
  4.                 If ctrl.Text = "" Then
  5.                     ctrl.Text = 0
  6.                 ElseIf (Not IsNumeric(ctrl.Text)) Then
  7.                     ctrl.Text = 0
  8.                 ElseIf (CInt(ctrl.Text) < 0) Then
  9.                     ctrl.Text = 0
  10.                 End If
  11.             End If
  12.         Next ctrl
  13.  
Mar 15 '08 #7
YeaY! Now it works!

Thank you very much! now I'm happy :p
Mar 15 '08 #8

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

Similar topics

4
by: Kevin H | last post by:
Apologies in advance if this sounds slow-witted, but I didn't find it here. Need to populate some textboxes on a form. While I could hard code it (the number of options aren't that high), it...
2
by: ozgirl via AccessMonster.com | last post by:
Hi, hopeing someone can help me here... I have a deductions table and form and want to be able to add many deductions to the table by having only a few fields on the form form fields:...
3
by: Belee | last post by:
I always clear textboxes by using eg this.txtName.clear(); What is the best way of doing this to about 20 boxes or asignig values to them in C#.
7
by: Hai Nguyen | last post by:
I have another question. I'm trying to loop through all the textboxes on a web application. The snippet is below //foreach(WebControl ctr in Page.Controls) foreach(Control ctr in Page.Controls)...
4
by: Deasun O'Donnachadha | last post by:
Good evening, I have a panel with a number of labels and textboxes. I want to set the text boxes to readonly = false. This is what I have; Dim objTxtBox As New TextBox For Each objTxtBox In...
4
by: Nick | last post by:
Hi - I'm trying to loop through the textboxes on a page to unlock them for editing. The Enabled property is set to false, and the following code is on an 'Edit' button on the form. Can anyone tell...
4
by: bwalke | last post by:
I am developing a web form which is going to be used for manufacturing input. The form uses a DataList which list a batch of parts that may range anywhere from 1-9 parts. The DataList contains 6 ...
0
by: jobs | last post by:
I have a many many pages with many formviews with many textboxes in them. The matrix of types of validation I need to do is a giant mess so please don't judge the code you are about to see - I...
6
by: jobs | last post by:
This code was working, but then stopped working. I don't think I completely understand it. I pass it a formview name and it would loop through checking the value of textboxes. problem is...
0
by: gurmeet07 | last post by:
if i have smthing like............. if (ht.ContainsKey(textBox7.Text)) { object array = (object)ht; textBox1.Text = (string)array; textBox2.Text = (string)array; textBox3Text = (string)array;...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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...
0
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
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...

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.