Solved

Textbox control

Posted on 1999-01-21
8
195 Views
Last Modified: 2013-11-13
Suppose I have 10 textbox on a single form.I don't
want to write code like this:

  text1.text = ""
  text2.text = ""
    |
    |
  text10.text = "" 

  I don't want hard coding(like "text1" or "text2"
  or..."text10").And also i want to make it blank.

Please give me solution with less coding. may be in a single line ?

With warm regards,

Nilesh shah

0
Comment
Question by:Aurokripa
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 1

Accepted Solution

by:
amithvs earned 50 total points
ID: 1469819
Try this....
Dim con As Control
For Each con In Form1
    If TypeOf con Is TextBox Then
    con.Text = ""
    End If
Next
0
 
LVL 1

Expert Comment

by:hddp666
ID: 1469820
You can also copy one textbox and paste over and over to create a control array, such as Text(1), Text(2), etc.

Dim i As Integer
For i = 0 to 9
   Text(i).Text = ""
Next i

0
 
LVL 2

Expert Comment

by:jrmcg
ID: 1469821
I would agree with hddp666, using the control array would also make operations easier down the line if the text box information is going to be related or similar.

J.R.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 12

Expert Comment

by:mark2150
ID: 1469822
Only change I'd make is that instead of coding "For i = 0 to 9" I'd code it "For i = Text1.Lbound TO Text1.Ubound" so it'll be dynamic as the control array size changes.

("For i ="??? Hmm, do I smell an old FORTRAN programmer out there? <G>)

M

0
 
LVL 1

Expert Comment

by:hddp666
ID: 1469823
Yeah, Fortran, Cobol, &c.
0
 
LVL 12

Expert Comment

by:mark2150
ID: 1469824
*thought so!* (grin) Old habits die hard, no?

M

0
 
LVL 1

Expert Comment

by:hddp666
ID: 1469825
Old habits don't die hard until after the faux-clever businessmen "save money" on engineers' and designers' salaries, right up to the brink of The Mother of All Crises, and then wind up paying dearly for the obsolete programming skills necessary to fix the "bargains" they obtained in the past 8-}

The Experts call this sort of behavior Penny-Wise and Krugerand-Foolish.

Ayn Rand called it Atlas Shrugged.
0
 
LVL 1

Expert Comment

by:amithvs
ID: 1469826
Maybe the user doesnt want to use control arrays as the text boxes may not be related.In that case the first option will only work
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question