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

Can anyone help in shortening this loop???

I am clearing Textboxes on a form... this is loop I have came up with
but was wondering if it can be shorter or not as long... Can anyone
help?

Dim controlOnForm As Control 'Places a control on the form
Dim controlOnTab As Control 'Places a control on the tab
Dim controlTabPage As Control 'Places a control on the tab
page
Dim controlGroupBox As Control 'Places a control on the group
box
For Each controlOnForm In Me.Controls 'Focus on the form
For Each controlOnTab In controlOnForm.Controls 'Focus on
the Tab
For Each controlTabPage In controlOnTab.Controls 'Focus

on the Tab Page
If TypeOf controlTabPage Is TextBox Then 'Focus on
the Textboxes
controlTabPage.Text = "" 'Clear Textbox
End If
If TypeOf controlTabPage Is ComboBox Then 'Focus on

the ComboBox
controlTabPage.Text = "" 'Clear ComboBox
End If
For Each controlGroupBox In controlTabPage.Controls

'Focus on the GroupBox
If TypeOf controlGroupBox Is TextBox Then
'Focus on the Textbox
controlGroupBox.Text = "" 'Clear Textbox
End If
Next
Next
Next
Next
Thought it would be easier in .NET than in VB6...

Aug 11 '06 #1
6 1549
Kberry,

You mean all textboxes as you showed on a form?

\\\
Private Sub Form5_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
doset(Me)
End Sub
Private Sub doSet(ByVal parentCtr As Control)
For Each ctr as Control In parentCtr.Controls
If TypeOf ctr = Textbox orelse TypeOf ctr = Combobox _
orelse Typeof ctr = ControlGroupBox then
ctr.text = ""
End if
doSet(ctr)
Next
End Sub
///

I hope this helps,

Cor
<kb****@processbarron.comschreef in bericht
news:11**********************@74g2000cwt.googlegro ups.com...
>I am clearing Textboxes on a form... this is loop I have came up with
but was wondering if it can be shorter or not as long... Can anyone
help?

Dim controlOnForm As Control 'Places a control on the form
Dim controlOnTab As Control 'Places a control on the tab
Dim controlTabPage As Control 'Places a control on the tab
page
Dim controlGroupBox As Control 'Places a control on the group
box
For Each controlOnForm In Me.Controls 'Focus on the form
For Each controlOnTab In controlOnForm.Controls 'Focus on
the Tab
For Each controlTabPage In controlOnTab.Controls 'Focus

on the Tab Page
If TypeOf controlTabPage Is TextBox Then 'Focus on
the Textboxes
controlTabPage.Text = "" 'Clear Textbox
End If
If TypeOf controlTabPage Is ComboBox Then 'Focus on

the ComboBox
controlTabPage.Text = "" 'Clear ComboBox
End If
For Each controlGroupBox In controlTabPage.Controls

'Focus on the GroupBox
If TypeOf controlGroupBox Is TextBox Then
'Focus on the Textbox
controlGroupBox.Text = "" 'Clear Textbox
End If
Next
Next
Next
Next
Thought it would be easier in .NET than in VB6...

Aug 11 '06 #2
An eloquent example of programming, Cor!

T
Cor Ligthert [MVP] wrote:
>Kberry,

You mean all textboxes as you showed on a form?

\\\
Private Sub Form5_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
doset(Me)
End Sub
Private Sub doSet(ByVal parentCtr As Control)
For Each ctr as Control In parentCtr.Controls
If TypeOf ctr = Textbox orelse TypeOf ctr = Combobox _
orelse Typeof ctr = ControlGroupBox then
ctr.text = ""
End if
doSet(ctr)
Next
End Sub
///

I hope this helps,

Cor
<kb****@processbarron.comschreef in bericht
news:11**********************@74g2000cwt.googlegr oups.com...

>>I am clearing Textboxes on a form... this is loop I have came up with
but was wondering if it can be shorter or not as long... Can anyone
help?

Dim controlOnForm As Control 'Places a control on the form
Dim controlOnTab As Control 'Places a control on the tab
Dim controlTabPage As Control 'Places a control on the tab
page
Dim controlGroupBox As Control 'Places a control on the group
box
For Each controlOnForm In Me.Controls 'Focus on the form
For Each controlOnTab In controlOnForm.Controls 'Focus on
the Tab
For Each controlTabPage In controlOnTab.Controls 'Focus

on the Tab Page
If TypeOf controlTabPage Is TextBox Then 'Focus on
the Textboxes
controlTabPage.Text = "" 'Clear Textbox
End If
If TypeOf controlTabPage Is ComboBox Then 'Focus on

the ComboBox
controlTabPage.Text = "" 'Clear ComboBox
End If
For Each controlGroupBox In controlTabPage.Controls

'Focus on the GroupBox
If TypeOf controlGroupBox Is TextBox Then
'Focus on the Textbox
controlGroupBox.Text = "" 'Clear Textbox
End If
Next
Next
Next
Next
Thought it would be easier in .NET than in VB6...

Aug 11 '06 #3
Cor,
About the only change I normally include is to check to see if the control
has children before I do the recursive call:

| Private Sub doSet(ByVal parentCtr As Control)
| For Each ctr as Control In parentCtr.Controls
| If TypeOf ctr = Textbox orelse TypeOf ctr = Combobox _
| orelse Typeof ctr = ControlGroupBox then
| ctr.text = ""
| End if
If ctr.HasChildren Then
| doSet(ctr)
End If
| Next
| End Sub

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:ed*************@TK2MSFTNGP05.phx.gbl...
| Kberry,
|
| You mean all textboxes as you showed on a form?
|
| \\\
| Private Sub Form5_Load(ByVal sender As Object, _
| ByVal e As System.EventArgs) Handles MyBase.Load
| doset(Me)
| End Sub
| Private Sub doSet(ByVal parentCtr As Control)
| For Each ctr as Control In parentCtr.Controls
| If TypeOf ctr = Textbox orelse TypeOf ctr = Combobox _
| orelse Typeof ctr = ControlGroupBox then
| ctr.text = ""
| End if
| doSet(ctr)
| Next
| End Sub
| ///
|
| I hope this helps,
|
| Cor
| <kb****@processbarron.comschreef in bericht
| news:11**********************@74g2000cwt.googlegro ups.com...
| >I am clearing Textboxes on a form... this is loop I have came up with
| but was wondering if it can be shorter or not as long... Can anyone
| help?
| >
| Dim controlOnForm As Control 'Places a control on the form
| Dim controlOnTab As Control 'Places a control on the tab
| Dim controlTabPage As Control 'Places a control on the tab
| page
| Dim controlGroupBox As Control 'Places a control on the group
| box
| For Each controlOnForm In Me.Controls 'Focus on the form
| For Each controlOnTab In controlOnForm.Controls 'Focus on
| the Tab
| For Each controlTabPage In controlOnTab.Controls 'Focus
| >
| on the Tab Page
| If TypeOf controlTabPage Is TextBox Then 'Focus on
| the Textboxes
| controlTabPage.Text = "" 'Clear Textbox
| End If
| If TypeOf controlTabPage Is ComboBox Then 'Focus on
| >
| the ComboBox
| controlTabPage.Text = "" 'Clear ComboBox
| End If
| For Each controlGroupBox In controlTabPage.Controls
| >
| 'Focus on the GroupBox
| If TypeOf controlGroupBox Is TextBox Then
| 'Focus on the Textbox
| controlGroupBox.Text = "" 'Clear Textbox
| End If
| Next
| Next
| Next
| Next
| >
| >
| Thought it would be easier in .NET than in VB6...
| >
|
|
Aug 13 '06 #4
Jay,

I am in doubt in this what I should use.

I like to avoid code which is done in the recursive call by the for each ctr
as the control has no children, on the other hand do I not know what time is
taken by building the stack and destroy it again.

Maybe I will make a test for this in short future.

Cor

"Jay B. Harlow [MVP - Outlook]" <Ja************@tsbradley.netschreef in
bericht news:uh**************@TK2MSFTNGP02.phx.gbl...
Cor,
About the only change I normally include is to check to see if the control
has children before I do the recursive call:

| Private Sub doSet(ByVal parentCtr As Control)
| For Each ctr as Control In parentCtr.Controls
| If TypeOf ctr = Textbox orelse TypeOf ctr = Combobox _
| orelse Typeof ctr = ControlGroupBox then
| ctr.text = ""
| End if
If ctr.HasChildren Then
| doSet(ctr)
End If
| Next
| End Sub

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
.NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:ed*************@TK2MSFTNGP05.phx.gbl...
| Kberry,
|
| You mean all textboxes as you showed on a form?
|
| \\\
| Private Sub Form5_Load(ByVal sender As Object, _
| ByVal e As System.EventArgs) Handles MyBase.Load
| doset(Me)
| End Sub
| Private Sub doSet(ByVal parentCtr As Control)
| For Each ctr as Control In parentCtr.Controls
| If TypeOf ctr = Textbox orelse TypeOf ctr = Combobox _
| orelse Typeof ctr = ControlGroupBox then
| ctr.text = ""
| End if
| doSet(ctr)
| Next
| End Sub
| ///
|
| I hope this helps,
|
| Cor
| <kb****@processbarron.comschreef in bericht
| news:11**********************@74g2000cwt.googlegro ups.com...
| >I am clearing Textboxes on a form... this is loop I have came up with
| but was wondering if it can be shorter or not as long... Can anyone
| help?
| >
| Dim controlOnForm As Control 'Places a control on the form
| Dim controlOnTab As Control 'Places a control on the tab
| Dim controlTabPage As Control 'Places a control on the tab
| page
| Dim controlGroupBox As Control 'Places a control on the group
| box
| For Each controlOnForm In Me.Controls 'Focus on the form
| For Each controlOnTab In controlOnForm.Controls 'Focus on
| the Tab
| For Each controlTabPage In controlOnTab.Controls 'Focus
| >
| on the Tab Page
| If TypeOf controlTabPage Is TextBox Then 'Focus on
| the Textboxes
| controlTabPage.Text = "" 'Clear Textbox
| End If
| If TypeOf controlTabPage Is ComboBox Then 'Focus on
| >
| the ComboBox
| controlTabPage.Text = "" 'Clear ComboBox
| End If
| For Each controlGroupBox In controlTabPage.Controls
| >
| 'Focus on the GroupBox
| If TypeOf controlGroupBox Is TextBox Then
| 'Focus on the Textbox
| controlGroupBox.Text = "" 'Clear Textbox
| End If
| Next
| Next
| Next
| Next
| >
| >
| Thought it would be easier in .NET than in VB6...
| >
|
|


Aug 13 '06 #5
Cor,
| I not know what time is
| taken by building the stack and destroy it again.
|
| Maybe I will make a test for this in short future.
The sample given was not intended as a performance preference, rather as an
alternative way of doing it.

I have also seen/used:

| | Private Sub doSet(ByVal parentCtr As Control)
If parentCtr.HasChildren Then
| | For Each ctr as Control In parentCtr.Controls
| | If TypeOf ctr = Textbox orelse TypeOf ctr = Combobox _
| | orelse Typeof ctr = ControlGroupBox then
| | ctr.text = ""
| | End if
| | Next
End If
| | End Sub

The first example, as you mention, avoids a recursive call.
The second example avoids creating an Enumerator, creating an Enumerator may
add to memory pressure...

Based on the 80/20 rule both may be pre-mature optimizations...

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
| Jay,
|
| I am in doubt in this what I should use.
|
| I like to avoid code which is done in the recursive call by the for each
ctr
| as the control has no children, on the other hand do I not know what time
is
| taken by building the stack and destroy it again.
|
| Maybe I will make a test for this in short future.
|
| Cor
|
| "Jay B. Harlow [MVP - Outlook]" <Ja************@tsbradley.netschreef in
| bericht news:uh**************@TK2MSFTNGP02.phx.gbl...
| Cor,
| About the only change I normally include is to check to see if the
control
| has children before I do the recursive call:
| >
| | Private Sub doSet(ByVal parentCtr As Control)
| | For Each ctr as Control In parentCtr.Controls
| | If TypeOf ctr = Textbox orelse TypeOf ctr = Combobox _
| | orelse Typeof ctr = ControlGroupBox then
| | ctr.text = ""
| | End if
| If ctr.HasChildren Then
| | doSet(ctr)
| End If
| | Next
| | End Sub
| >
| >
| >
| --
| Hope this helps
| Jay B. Harlow [MVP - Outlook]
| .NET Application Architect, Enthusiast, & Evangelist
| T.S. Bradley - http://www.tsbradley.net
| >
| >
| "Cor Ligthert [MVP]" <no************@planet.nlwrote in message
| news:ed*************@TK2MSFTNGP05.phx.gbl...
| | Kberry,
| |
| | You mean all textboxes as you showed on a form?
| |
| | \\\
| | Private Sub Form5_Load(ByVal sender As Object, _
| | ByVal e As System.EventArgs) Handles MyBase.Load
| | doset(Me)
| | End Sub
| | Private Sub doSet(ByVal parentCtr As Control)
| | For Each ctr as Control In parentCtr.Controls
| | If TypeOf ctr = Textbox orelse TypeOf ctr = Combobox _
| | orelse Typeof ctr = ControlGroupBox then
| | ctr.text = ""
| | End if
| | doSet(ctr)
| | Next
| | End Sub
| | ///
| |
| | I hope this helps,
| |
| | Cor
| | <kb****@processbarron.comschreef in bericht
| | news:11**********************@74g2000cwt.googlegro ups.com...
| | >I am clearing Textboxes on a form... this is loop I have came up with
| | but was wondering if it can be shorter or not as long... Can anyone
| | help?
| | >
| | Dim controlOnForm As Control 'Places a control on the form
| | Dim controlOnTab As Control 'Places a control on the tab
| | Dim controlTabPage As Control 'Places a control on the tab
| | page
| | Dim controlGroupBox As Control 'Places a control on the
group
| | box
| | For Each controlOnForm In Me.Controls 'Focus on the form
| | For Each controlOnTab In controlOnForm.Controls 'Focus on
| | the Tab
| | For Each controlTabPage In controlOnTab.Controls
'Focus
| | >
| | on the Tab Page
| | If TypeOf controlTabPage Is TextBox Then 'Focus
on
| | the Textboxes
| | controlTabPage.Text = "" 'Clear Textbox
| | End If
| | If TypeOf controlTabPage Is ComboBox Then 'Focus
on
| | >
| | the ComboBox
| | controlTabPage.Text = "" 'Clear ComboBox
| | End If
| | For Each controlGroupBox In
controlTabPage.Controls
| | >
| | 'Focus on the GroupBox
| | If TypeOf controlGroupBox Is TextBox Then
| | 'Focus on the Textbox
| | controlGroupBox.Text = "" 'Clear Textbox
| | End If
| | Next
| | Next
| | Next
| | Next
| | >
| | >
| | Thought it would be easier in .NET than in VB6...
| | >
| |
| |
| >
| >
|
|
Aug 13 '06 #6
kb****@processbarron.com wrote:
I am clearing Textboxes on a form... this is loop I have came up with
but was wondering if it can be shorter or not as long... Can anyone
help?

Dim controlOnForm As Control 'Places a control on the form
Dim controlOnTab As Control 'Places a control on the tab
Dim controlTabPage As Control 'Places a control on the tab
page
Dim controlGroupBox As Control 'Places a control on the group
box
For Each controlOnForm In Me.Controls 'Focus on the form
For Each controlOnTab In controlOnForm.Controls 'Focus on
the Tab
For Each controlTabPage In controlOnTab.Controls 'Focus

on the Tab Page
If TypeOf controlTabPage Is TextBox Then 'Focus on
the Textboxes
controlTabPage.Text = "" 'Clear Textbox
End If
If TypeOf controlTabPage Is ComboBox Then 'Focus on

the ComboBox
controlTabPage.Text = "" 'Clear ComboBox
End If
For Each controlGroupBox In controlTabPage.Controls

'Focus on the GroupBox
If TypeOf controlGroupBox Is TextBox Then
'Focus on the Textbox
controlGroupBox.Text = "" 'Clear Textbox
End If
Next
Next
Next
Next
Thought it would be easier in .NET than in VB6...
I don't know if this is possible in your case, but here's something i
just implemented.

Bind all the textboxes to different DataColumns in a DataTable. To
clear the text, do a DataTable.Clear.

Works like a charm.

B.

Aug 14 '06 #7

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

Similar topics

2
by: kaptain kernel | last post by:
how does one shorten an array based on a key value. Say I have this: array("Car1"=>"Porsche","Car2"=>"Merc","Car3"=>"Ford","Car4"=>"Toyota"); and I want to pop "Car2" out of the array,...
9
by: blah | last post by:
i m trying to reverse the order in which the strings are stored in list then pop it into another list what m i doin worng?? here's the code: list1 =
0
by: pointBoarder | last post by:
So I'm new to access and I keep getting this "catastrophic error" when running this function. I my mind, all I'm doing is a nested for each loop with RecordSets Vs collections. The kicker is,...
33
by: Larry | last post by:
Does anyone use the 3rd party utility CodeRush for VStudio? If so then I would like to see how well it is loved or hated. I have been using the trial for a week and I have a mixed opinion about...
4
by: Paul H | last post by:
OK, I tried getting and old Newbury Data ND2500 working using the "Generic /Text only" driver in Win XP. It prints, but I could not find a way to set a custom page size that matches the paper I am...
5
by: tony | last post by:
I'm using PHP 5 on Win-98 command line (ie no web server involved) I'm processing a large csv file and when I loop through it I can process around 275 records per second. However at around...
4
by: eking | last post by:
//Thanks for any help,thank you!лл¡£ public override void FloodFill(Bitmap bmp, Point pt) { int ctr=timeGetTime(); //Debug.WriteLine("*******Flood Fill******"); //get the color's int...
18
by: miller.paul.w | last post by:
Ruby has a neat little convenience when writing loops where you don't care about the loop index: you just do n.times do { ... some code ... } where n is an integer representing how many times you...
5
by: lawrencef | last post by:
I’m new to JavaScript and am trying to creating a dynamic web form in a number of layers. From what I've read, to submit the entire form I need to have all the fields (that are in all the different...
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?
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
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
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,...
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...
0
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...
0
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
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,...

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.