473,797 Members | 3,126 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.C ontrols 'Focus on
the Tab
For Each controlTabPage In controlOnTab.Co ntrols '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 1571
Kberry,

You mean all textboxes as you showed on a form?

\\\
Private Sub Form5_Load(ByVa l sender As Object, _
ByVal e As System.EventArg s) Handles MyBase.Load
doset(Me)
End Sub
Private Sub doSet(ByVal parentCtr As Control)
For Each ctr as Control In parentCtr.Contr ols
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****@process barron.comschre ef in bericht
news:11******** **************@ 74g2000cwt.goog legroups.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.C ontrols 'Focus on
the Tab
For Each controlTabPage In controlOnTab.Co ntrols '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(ByVa l sender As Object, _
ByVal e As System.EventArg s) Handles MyBase.Load
doset(Me)
End Sub
Private Sub doSet(ByVal parentCtr As Control)
For Each ctr as Control In parentCtr.Contr ols
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****@proces sbarron.comschr eef in bericht
news:11******* *************** @74g2000cwt.goo glegroups.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.C ontrols 'Focus on
the Tab
For Each controlTabPage In controlOnTab.Co ntrols '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.Contr ols
| 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******** *****@TK2MSFTNG P05.phx.gbl...
| Kberry,
|
| You mean all textboxes as you showed on a form?
|
| \\\
| Private Sub Form5_Load(ByVa l sender As Object, _
| ByVal e As System.EventArg s) Handles MyBase.Load
| doset(Me)
| End Sub
| Private Sub doSet(ByVal parentCtr As Control)
| For Each ctr as Control In parentCtr.Contr ols
| 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****@process barron.comschre ef in bericht
| news:11******** **************@ 74g2000cwt.goog legroups.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.C ontrols 'Focus on
| the Tab
| For Each controlTabPage In controlOnTab.Co ntrols '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.nets chreef in
bericht news:uh******** ******@TK2MSFTN GP02.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.Contr ols
| 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******** *****@TK2MSFTNG P05.phx.gbl...
| Kberry,
|
| You mean all textboxes as you showed on a form?
|
| \\\
| Private Sub Form5_Load(ByVa l sender As Object, _
| ByVal e As System.EventArg s) Handles MyBase.Load
| doset(Me)
| End Sub
| Private Sub doSet(ByVal parentCtr As Control)
| For Each ctr as Control In parentCtr.Contr ols
| 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****@process barron.comschre ef in bericht
| news:11******** **************@ 74g2000cwt.goog legroups.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.C ontrols 'Focus on
| the Tab
| For Each controlTabPage In controlOnTab.Co ntrols '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.HasCh ildren Then
| | For Each ctr as Control In parentCtr.Contr ols
| | 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******** ********@TK2MSF TNGP02.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.nets chreef in
| bericht news:uh******** ******@TK2MSFTN GP02.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.Contr ols
| | 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******** *****@TK2MSFTNG P05.phx.gbl...
| | Kberry,
| |
| | You mean all textboxes as you showed on a form?
| |
| | \\\
| | Private Sub Form5_Load(ByVa l sender As Object, _
| | ByVal e As System.EventArg s) Handles MyBase.Load
| | doset(Me)
| | End Sub
| | Private Sub doSet(ByVal parentCtr As Control)
| | For Each ctr as Control In parentCtr.Contr ols
| | 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****@process barron.comschre ef in bericht
| | news:11******** **************@ 74g2000cwt.goog legroups.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.C ontrols 'Focus on
| | the Tab
| | For Each controlTabPage In controlOnTab.Co ntrols
'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****@processb arron.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.C ontrols 'Focus on
the Tab
For Each controlTabPage In controlOnTab.Co ntrols '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
4909
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, leaving the rest of the elements. array_pop appears to just pop the last element off the array - I want to pop ANY element out of the array, thus shortening it.
9
1449
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
1228
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, this string will work fine: ' curLine = "call AddBom(""" + inParent + """, """ + curChild + """,""" + curQty + """)" But this one give me a "catastrophic error" 'curLine = "call AddBom(""" + inParent + """, """ + curChild +
33
2712
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 it, neither love nor hate. Thanks, Larry.
4
1895
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 using. So there was no way it would ever work. The customer is happy to buy another Dot Matrix printer because the ND2500 can be used elsewhere. So which printer should I get that can plug and play with Access? Paul
5
2729
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 6,000 records this suddenly drops off to around 40 records per second. This is a big problem as the "live" list is over 4 million records long. I'd break it up but this is to be a regular test so that would be messy
4
2218
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 value, and convert it from RGBA to BGRA format (as GDI+ uses BGRA)
18
1463
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 want to execute "some code." In Python, the direct translation of this is a for loop. When the index doesn't matter to me, I tend to write it as: for _ in xrange (1,n): some code
5
1102
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 layers on the page), present in the main form as hidden fields. I've done this and now and trying to write a function to loop through all the layers on the page and then all the elements within those layers and copy the field value to the hidden...
0
9685
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9536
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10468
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
10245
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...
0
10021
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...
0
9063
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5458
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...
2
3748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2933
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.