467,115 Members | 1,279 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,115 developers. It's quick & easy.

using objects in visual basic

Hi all,
i need to clear multiple text box using a single button click how can it be done using objects
Nov 9 '06 #1
  • viewed: 1149
Share:
3 Replies
100+
Hi all,
i need to clear multiple text box using a single button click how can it be done using objects
hi

try

private sub object_click()
text1.text=vbnullstring
text2.text=vbnullstring
etc

end sub
Nov 9 '06 #2
1GB
Hi all,
i need to clear multiple text box using a single button click how can it be done using objects
A standard way of doing this is as follows:
Expand|Select|Wrap|Line Numbers
  1. Dim ctrl As Control
  2.  
  3. For Each ctrl In Me.Controls
  4.    If TypeName(ctrl) = "TextBox" Then
  5.       ctrl.Text = ""
  6.    End If
  7. Next ctrl
  8.  
Nov 9 '06 #3
Expert 8TB
A standard way of doing this is as follows: ...
You can make this kind of thing a common routine to be included in your bag of tricks, for use in any program. To make it more generally applicable, you can allow it to target specific controls. One simple way is to place something in their .Tag property for it to recognise.

For example, if you pass your form to this sub, it will only hit those textboxes which have "/CLEARME" somewhere in their tag.
Expand|Select|Wrap|Line Numbers
  1. Public Sub ClearTextBoxes(frm As Form)
  2.   Dim ctrl As Control
  3.   For Each ctrl In frm.Controls
  4.     If TypeName(ctrl) = "TextBox" Then
  5.       If InStr(ctrl.Tag, "/CLEARME") Then
  6.         ctrl.Text = ""
  7.       End If
  8.     End If
  9.   Next ctrl
  10. End Sub
To call it from a button on the form, for instance, you would just say
Expand|Select|Wrap|Line Numbers
  1. ClearTextBoxes Me
Nov 9 '06 #4

Post your reply

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

Similar topics

14 posts views Thread by Curtis Tammany | last post: by
121 posts views Thread by typingcat@gmail.com | last post: by
2 posts views Thread by news@visual-basic-data-mining.net | last post: by
1 post views Thread by Screenbert | last post: by
reply views Thread by screenbert@gmail.com | last post: by
1 post views Thread by =?Utf-8?B?TWFyaw==?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.