Solved

Textbox control

Posted on 1999-01-21
8
185 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

910 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now