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

for each...in...

How can I test all my textboxes in my form wether they
are empty are not by using a for each... in .. structure
in VB.Net?

Nov 20 '05 #1
12 1649
Cor
Hi Java,
How can I test all my textboxes in my form wether they
are empty are not by using a for each... in .. structure
in VB.Net?


When all textboxes are on the main form (windowform)
Rough written so don't look at typo's
\\\
dim ctr as control
for each ctr in me.controls
if typeof ctr is textbox then
if ctr.text <>"" then
'do something
end if
end if
next
///
If it is a webform "text" is not in the control and you have to cast it
first, but that is a problem itself, but I thought I have somewhere saved a
solution, so tell that than again.

I hope this helps a little bit,

Cor
Nov 20 '05 #2
Hi,

Dim ctrl As Control

For Each ctrl In Me.Controls

If TypeOf (ctrl) Is TextBox Then

Dim tb As TextBox = ctrl

If tb.Text = "" Then

tb.Text = "Empty"

End If

End If

Next

Ken

---------------------------------------

"koffietje" <an*******@discussions.microsoft.com> wrote in message
news:07****************************@phx.gbl...
How can I test all my textboxes in my form wether they
are empty are not by using a for each... in .. structure
in VB.Net?

Nov 20 '05 #3
* "Ken Tucker [MVP]" <vb***@bellsouth.net> scripsit:
If TypeOf (ctrl) Is TextBox Then


Just FYI: You don't need the "(", ")" around 'ctrl'.

;-)

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #4
* "koffietje" <an*******@discussions.microsoft.com> scripsit:
How can I test all my textboxes in my form wether they
are empty are not by using a for each... in .. structure
in VB.Net?


<http://www.mvps.org/dotnet/dotnet/samples/controls/downloads/EnumerateControls.zip>

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #5
"koffietje" <an*******@discussions.microsoft.com> schrieb
How can I test all my textboxes in my form wether they
are empty are not by using a for each... in .. structure
in VB.Net?


You do need a loop. Either for each..next, for..next, do while...
--
Armin

Nov 20 '05 #6
Hi Ken, exactly what I was looking for! Thanks!

-----Original Message-----
Hi,

Dim ctrl As Control

For Each ctrl In Me.Controls

If TypeOf (ctrl) Is TextBox Then

Dim tb As TextBox = ctrl

If tb.Text = "" Then

tb.Text = "Empty"

End If

End If

Next

Ken

---------------------------------------

"koffietje" <an*******@discussions.microsoft.com> wrote in messagenews:07****************************@phx.gbl...
How can I test all my textboxes in my form wether they
are empty are not by using a for each... in .. structure in VB.Net?

.

Nov 20 '05 #7
Hi, Cor, all the information I needed ! thanks
-----Original Message-----
Hi Java,
How can I test all my textboxes in my form wether they
are empty are not by using a for each... in .. structure in VB.Net?
When all textboxes are on the main form (windowform)
Rough written so don't look at typo's
\\\
dim ctr as control
for each ctr in me.controls
if typeof ctr is textbox then
if ctr.text <>"" then
'do something
end if
end if
next
///
If it is a webform "text" is not in the control and you

have to cast itfirst, but that is a problem itself, but I thought I have somewhere saved asolution, so tell that than again.

I hope this helps a little bit,

Cor
.

Nov 20 '05 #8
Hi Fergus,
Great information, thanks a lot!

-----Original Message-----
Hi Koffietje,

You need one of two methods depending on whether your TextBoxes aredirectly on the Form or whether some are held within other Controls such asPanels.

If all the TextBoxes are directly on the Form then the methods shown byCor and Ken will be fine.

If there are any TextBoxes inside other Controls then a recursive methodis required: An example is shown below. Form is a Control so it starts offwith the Form passing itself (Me).

In the Form:
CheckTheTextBoxes (Me)
Sub CheckTheTextBoxes (oControl As Control)
Dim oChildControl As Control
For Each oChildControl in oControl.Controls
If TypeOf (oChildControl) Is TextBox _
AndAlso oChildControl.Text = "" Then 'or use <> 'Take some action.
End If
CheckTheTextBoxes (oChildControl) 'Check Panels, etc. Next
End Sub

You can use:
Dim oTextBox As TextBox = oChildControl
in the 'Take some action' section if you actually need to do anything'textboxy'.

Regards,
Fergus

If you use Option Strict On, you'll need
Dim oTextBox As TextBox = DirectCast (oChildControl, TextBox)

.

Nov 20 '05 #9
Thanks a lot !!
-----Original Message-----
* "koffietje" <an*******@discussions.microsoft.com> scripsit:
How can I test all my textboxes in my form wether they
are empty are not by using a for each... in .. structure in VB.Net?


<http://www.mvps.org/dotnet/dotnet/sa...controls/downl

oads/EnumerateControls.zip>
--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
.

Nov 20 '05 #10
* "koffietje" <an*******@discussions.microsoft.com> scripsit:
Hi Ken, exactly what I was looking for! Thanks!


Notice that this code will not enumerate nested controls.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

Improve your quoting style:
<http://learn.to/quote>
<http://www.plig.net/nnq/nquote.html>
Nov 20 '05 #11
Cor
Hi Herfried,

Notice that this code will not enumerate nested controls.


But the answer from Fergus does and Java was answering that also

Cor
Nov 20 '05 #12
* "Cor" <no*@non.com> scripsit:
Notice that this code will not enumerate nested controls.


But the answer from Fergus does and Java was answering that also


I know that...

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

Improve your quoting style:
<http://learn.to/quote>
<http://www.plig.net/nnq/nquote.html>
Nov 20 '05 #13

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

Similar topics

4
by: Jean-Christophe Michel | last post by:
Hi, I have a stylesheet with an accumulator like this <xsl:param name="new-x"> <xsl:for-each select="anode"> <mynode> <xsl:attribute name="attr"> <xsl:value select="anode/atag" />...
2
by: matatu | last post by:
Hi to everybody, It's possible to exit from a cycle for-each? I have this code: 1: <xsl:for-each select="field"> 2: <xsl:variable name="tagfield" select="@tag"/> 3: <xsl:variable...
3
by: deko | last post by:
Problem: why doesn't this With block work? is it possible to have a For Each loop within a With block? With objWord .Documents.Add Template:=strTemplate, NewTemplate:=False, DocumentType:=0...
8
by: Floris van Haaster | last post by:
Hi All! I have a question, i have a web application and I store some member information in a variable i declared in a module like: Public some_info_variable as string in module1.vb But...
13
by: tshad | last post by:
Is there a way to run a script or function on entry of each page without having to put a call in each page? Periodically, I find something I want to do each time a page is entered and I have to...
6
by: Michael D. Ober | last post by:
In VB 6, the loop iterator v in the following code must be a variant. dim v as variant dim c as new collection for each v in collection ... next v What is the general translation in VB 7.1...
6
by: Neal | last post by:
Hi All, I used an article on XSLT and XML and creating a TOC written on the MSDN CodeCorner. ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/dncodecorn/html/corner042699.htm However, it did'nt...
9
by: xmlhelp | last post by:
stuff.XSL: <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:param name="uid"/> <xsl:template match="/"> parameter...
17
by: The Frog | last post by:
Hello everyone, I am working on an application that can build database objects in MS Access from text files. I suppose you could call it a backup and restore type routine. Accessing the...
0
ADezii
by: ADezii | last post by:
If you want to visit each item in an Array, you have two alternatives: Use a For Each..Next loop, using a Variant to retrieve each value in turn. Use a For...Next loop, looping from the Lower...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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...
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.