473,804 Members | 3,321 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Resetting alll controls on a form

Hi Everyone.
I was using the following code in VB6, but am in the middle of converting
the app to VB.Net 2005. He is the code
Private Sub ClearAll()
On Error GoTo Error_Routine
Call appLogger("Clea rAll", "FrmPatientInfo ")
Dim lcol As Control
isLoading = True
For Each lcol In Me.Controls
If TypeOf lcol Is TextBox Then
lcol.Text = ""
lcol.Tag = ""
ElseIf TypeOf lcol Is Image Then
lcol.Picture = LoadPicture(Def aultImage, vbLPCustom, vbLPDefault)
lcol.Tag = ""
ElseIf TypeOf lcol Is TDBMask Then
lcol.Text = ""
lcol.Tag = ""
ElseIf TypeOf lcol Is OptionButton Then
lcol.Value = False
lcol.Tag = ""
ElseIf TypeOf lcol Is TDBCombo Then
lcol.Text = ""
lcol.Tag = ""
ElseIf TypeOf lcol Is CheckBox Then
lcol.Value = 0
lcol.Tag = ""
ElseIf TypeOf lcol Is TDBDate Then
lcol.Value = Null
lcol.Tag = ""
ElseIf TypeOf lcol Is Label Then
If lcol.BackColor = &HFFF3E8 Then
lcol.Caption = ""
lcol.Tag = ""
End If
ElseIf TypeOf lcol Is ComboBox Then
lcol.Text = ""
lcol.Listindex = -1
lcol.Tag = ""
ElseIf TypeOf lcol Is CheckBox Then
End If
Next
isLoading = False
imgPatient.Tag = ""
Exit_Routine:
Exit Sub
Error_Routine:
Debug.Assert False
Errorlog "frmPatientInfo .ClearAll"
End Sub

I'd like it to clear the controls depending on the control, as you can see
above. I'm getting errors in VB.net that a property is not a member of
Control. Oneone got some suggestions. Thanks.
Michael Lee

Sep 7 '07 #1
2 1792
That is because Option Strict is on by default in VB.NET.

Either turn Option Strict Off, easier, but not recommended solution.

Or, Cast ICol to the correct type, ie. TextBox etc. (using DirectCast or
other methods) before resetting the properties for each control.

--
Rgds,
Anand
VB.NET MVP
http://www.dotnetindia.com
"Michael" wrote:
Hi Everyone.
I was using the following code in VB6, but am in the middle of converting
the app to VB.Net 2005. He is the code
Private Sub ClearAll()
On Error GoTo Error_Routine
Call appLogger("Clea rAll", "FrmPatientInfo ")
Dim lcol As Control
isLoading = True
For Each lcol In Me.Controls
If TypeOf lcol Is TextBox Then
lcol.Text = ""
lcol.Tag = ""
ElseIf TypeOf lcol Is Image Then
lcol.Picture = LoadPicture(Def aultImage, vbLPCustom, vbLPDefault)
lcol.Tag = ""
ElseIf TypeOf lcol Is TDBMask Then
lcol.Text = ""
lcol.Tag = ""
ElseIf TypeOf lcol Is OptionButton Then
lcol.Value = False
lcol.Tag = ""
ElseIf TypeOf lcol Is TDBCombo Then
lcol.Text = ""
lcol.Tag = ""
ElseIf TypeOf lcol Is CheckBox Then
lcol.Value = 0
lcol.Tag = ""
ElseIf TypeOf lcol Is TDBDate Then
lcol.Value = Null
lcol.Tag = ""
ElseIf TypeOf lcol Is Label Then
If lcol.BackColor = &HFFF3E8 Then
lcol.Caption = ""
lcol.Tag = ""
End If
ElseIf TypeOf lcol Is ComboBox Then
lcol.Text = ""
lcol.Listindex = -1
lcol.Tag = ""
ElseIf TypeOf lcol Is CheckBox Then
End If
Next
isLoading = False
imgPatient.Tag = ""
Exit_Routine:
Exit Sub
Error_Routine:
Debug.Assert False
Errorlog "frmPatientInfo .ClearAll"
End Sub

I'd like it to clear the controls depending on the control, as you can see
above. I'm getting errors in VB.net that a property is not a member of
Control. Oneone got some suggestions. Thanks.
Michael Lee
Sep 7 '07 #2
Michael wrote:
Dim lcol As Control
For Each lcol In Me.Controls
If TypeOf lcol Is TextBox Then
lcol.Text = ""
lcol.Tag = ""
ElseIf TypeOf lcol Is Image Then
lcol.Picture = LoadPicture(Def aultImage, vbLPCustom, vbLPDefault)
lcol.Tag = ""
You're /so/ nearly there.
Having asked the Control what Type it is, you just have to convince the
compiler that it should treat the given Control in that specific way.
DirectCast is quickest (AFAIK):

For Each col As Control _
In Me.Controls
If TypeOf col Is TextBox Then
With DirectCast( col, TextBox )
.Text = String.Empty
.Tag = String.Empty
End With

ElseIf TypeOf col Is Image Then
With DirectCast( col, Image )
.Picture = LoadPicture(Def aultImage, vbLPCustom, vbLPDefault)
.Tag = String.Empty
End With
. . .

IIRC, the Control Type defines the Tag property, so you could set this
one /outside/ the TypeOf checks.

HTH,
Phill W.
Sep 10 '07 #3

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

Similar topics

2
1817
by: DeveloperPDX | last post by:
I am creating a page and I need to add a reset button (like you would with HTML forms). Is there any way to do this other than resetting individual controls? Basically I need to page to return to the state after the OnLoad event
1
1437
by: Hrvoje Vrbanc | last post by:
Hello all! I have the following question: what's the easiest way to reset the content of an ASP.NET web form from within some event handler (e.g. DropDownList_SelectedIndexChanged) in the code behind file? I have a web form that has plenty of text fields populated by records from a database. When a week is chosen from a drop down list, results of the query are displayed in text boxes. However, there are no records in the database for...
1
14385
by: NancyASAP | last post by:
Thought I'd share this since it took me a long time to get it working. Thanks to a bunch of contributers in Google Groups who shared javascript, etc. The question was: How can I put a reset button on my ASP.NET web page, and have an HTML reset button click clear 1) all validator text display and 2) validation summary display. Problem was clearing them and yet still leaving them working and visible if the user immediately began...
8
1874
by: Nathan Sokalski | last post by:
I have a System.Web.UI.HtmlControls.HtmlInputFile control that I use to submit files. After the file is successfully submitted, I want the field to be reset so that the user knows the file was submitted. However, ASP.NET does not let you change the Value property of an HtmlInputFile control. How can I reset the HtmlInputFile control to it's original state? Thanks. -- Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/
4
4086
by: Ian Davies | last post by:
Hello I am struggling for a solution to clear some fields on my webpage that takes their values from some sessions My solution below works when the button is clicked twice. I sort of know why I have to click it twice to do the job (the first submit resets the sessions but this it too late to change the field values, which requires another submit to pick up the new session values). Problem is I cant think how to accomplish the resetting of...
8
2879
by: Kevin | last post by:
I'm using a form where users can input a bunch of info into unbound text controls that are used in series of calculations. At the bottom is a "reset" button. I want to clear out all of the user inputs on the form by clicking the button. Me.Refresh .requery .repaint do not work. Any suggestions?
1
1888
by: AB | last post by:
I am creating a ASP.Net 1.1 (VB) web. I have 2 drop down lists which are independent of each other. Both are filled from a database on the pageload. There is also a search button which searches the database based on the 2 drop down list entries. The first entry in each drop down list is "Please Select". What I am trying to do via client side script is to reset the unselected drop down list when the other drop down list selects a new...
0
949
by: Newbie5555 | last post by:
I'm having problem with my current webmaster. Iooking at changing. Current webmaster says he and only he can do the resetting licensing on the controls we use. Is that true? I can't get a stranght answer out of anyone. I know he uses Infragistic2 7ver. controls. Licensing is only done on the creation side not the user side on webdesign. right? Please help. Thanks
1
2910
by: =?Utf-8?B?UmljaA==?= | last post by:
I placed a button on a form menustrip for the purpose of causing the horizontal scrollbar of my form to appear so that I can access controls outside of the form's current view (the controls are further to the right of the form than the form's default width - which may take up the entire screen for some users). The form contains panels which will contain either textboxes or datagridviews. The button is located on the menustrip towards...
0
9575
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
10564
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
10320
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
10073
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
7609
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
5645
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4288
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3806
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2981
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.