banner



How To Clear A Textbox In Visual Basic

11 Replies - 1436 Views - Last Post: 29 May 2010 - 07:07 AM Rate Topic: - - - - -

#1

  • D.I.C Head

Reputation: -5

  • View blog
  • Posts: 142
  • Joined: 24-October 09

How to clear TextBox1-5 with easy way

Posted 28 May 2010 - 01:01 PM

Hello,

I want to know how to clear 5 TextBoxes with 1 line code not for every TextBox (TextBox.Text = ""). I tryed many methods, but not successfully.

Thanks,

Is This A Good Question/Topic? 0

  • +

Replies To: How to clear TextBox1-5 with easy way

#2 CharlieMay User is offline

Reputation: 1734

  • View blog
  • Posts: 5,710
  • Joined: 25-September 09

Re: How to clear TextBox1-5 with easy way

Posted 28 May 2010 - 01:15 PM

Here's a start... not one line of code but it will work

For Each txt As Control In Me.Controls             If TypeOf txt Is TextBox Then                 CType(txt, TextBox).Text = ""             End If Next                


#3 camckee316 User is offline

  • D.I.C Regular

Reputation: 15

  • View blog
  • Posts: 294
  • Joined: 29-August 08

Re: How to clear TextBox1-5 with easy way

Posted 28 May 2010 - 01:59 PM

If you really want one line of code:

TextBox1.Text And TextBox2.Text And TextBox3.Text And TextBox4.Text And TextBox5.Text =""                

Although I would recommend CharlieMay's way.


#4 CharlieMay User is offline

Reputation: 1734

  • View blog
  • Posts: 5,710
  • Joined: 25-September 09

Re: How to clear TextBox1-5 with easy way

Posted 28 May 2010 - 05:17 PM

LOL!, camckee316, I honestly had no idea you could even do that.


#5 camckee316 User is offline

  • D.I.C Regular

Reputation: 15

  • View blog
  • Posts: 294
  • Joined: 29-August 08

Re: How to clear TextBox1-5 with easy way

Posted 28 May 2010 - 06:37 PM

Actually you can't. It puts the blue line under it and say "Property access must assign to the property or use its value." I have would with it and tried, after the code was posted of course, that was all that I could think of at the time and I was not able to test it. I have also tried to use And; And Also; and & but they were a not also.


#6 _HAWK_ User is offline

Reputation: 1162

  • View blog
  • Posts: 4,444
  • Joined: 02-July 08

Re: How to clear TextBox1-5 with easy way

Posted 28 May 2010 - 07:23 PM

If your textboxes were the default names i.e. textbox1, textbox2, etc... Then this would work:

For i As Integer = 1 To 5    Me.Controls("textbox" & i.ToString).Text = "" Next                


#7 qtex User is offline

  • D.I.C Head

Reputation: -5

  • View blog
  • Posts: 142
  • Joined: 24-October 09

Re: How to clear TextBox1-5 with easy way

Posted 29 May 2010 - 04:24 AM

View Posthawkvalley1, on 28 May 2010 - 06:23 PM, said:

If your textboxes were the default names i.e. textbox1, textbox2, etc... Then this would work:

For i As Integer = 1 To 5    Me.Controls("textbox" & i.ToString).Text = "" Next                  

I have already tryed to do it with that way, but if i test that button then VB shows some kind of error and its dont work.
Anyway thanks for asnwering


#8 _HAWK_ User is offline

Reputation: 1162

  • View blog
  • Posts: 4,444
  • Joined: 02-July 08

Re: How to clear TextBox1-5 with easy way

Posted 29 May 2010 - 05:45 AM

This technique works for frameworks > 2.0. If your are getting an error tell us what it is, and show your code so we can see why this is occurring.


#9 qtex User is offline

  • D.I.C Head

Reputation: -5

  • View blog
  • Posts: 142
  • Joined: 24-October 09

Re: How to clear TextBox1-5 with easy way

Posted 29 May 2010 - 05:56 AM

View Posthawkvalley1, on 29 May 2010 - 04:45 AM, said:

This technique works for frameworks > 2.0. If your are getting an error tell us what it is, and show your code so we can see why this is occurring.

Ok , i use better framework than 2.0 . I use Visual Basic 2010.
and error :

"Object reference not set to an instance of an object."}


#10 _HAWK_ User is offline

Reputation: 1162

  • View blog
  • Posts: 4,444
  • Joined: 02-July 08

Re: How to clear TextBox1-5 with easy way

Posted 29 May 2010 - 05:59 AM

Then your textbox name does not match your code, check the names!


#11 qtex User is offline

  • D.I.C Head

Reputation: -5

  • View blog
  • Posts: 142
  • Joined: 24-October 09

Re: How to clear TextBox1-5 with easy way

Posted 29 May 2010 - 06:09 AM

View Posthawkvalley1, on 29 May 2010 - 04:59 AM, said:

Then your textbox name does not match your code, check the names!

All TextBoxes 1-5 have name

TextBox1
TextBox2
TextBox3

and etc...


#12 _HAWK_ User is offline

Reputation: 1162

  • View blog
  • Posts: 4,444
  • Joined: 02-July 08

Re: How to clear TextBox1-5 with easy way

Posted 29 May 2010 - 07:07 AM

That formula is case sensitive, that part ok?


  • ← Previous Topic
  • VB.NET
  • Next Topic →

How To Clear A Textbox In Visual Basic

Source: https://www.dreamincode.net/forums/topic/175531-how-to-clear-textbox1-5-with-easy-way/

Posted by: allenanothe.blogspot.com

0 Response to "How To Clear A Textbox In Visual Basic"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel