Go Back  Xtreme Visual Basic Talk > Visual Basic .NET (2002/2003/2005/2008, including Express editions) > .NET General > Checkboxes and text adding


Reply
 
Thread Tools Display Modes
  #1  
Old 12-16-2010, 03:17 PM
s0mewhiteguy7 s0mewhiteguy7 is offline
Newcomer
 
Join Date: Dec 2010
Posts: 7
Question Checkboxes and text adding


so i am making this program for this guy i know and i am making it to where of check box1 is checked then it adds the text in textbox2 to textbox1 so you can copy and paste...but i have more then one checkbox so if i check 2 of them it makes it to where it only shows the text for the last check box that was checked...here is my script:

(the text is added/updated when you click on button1)
Code:
If CheckBox1.Checked Then TextBox1.Text = TextBox2.Text If CheckBox2.Checked Then TextBox1.Text = TextBox3.Text If CheckBox3.Checked Then TextBox1.Text = TextBox4.Text If CheckBox4.Checked Then TextBox1.Text = TextBox5.Text If CheckBox5.Checked Then TextBox1.Text = TextBox6.Text End If End If End If End If End If End Sub End Class
i dont know what to do

Last edited by Gruff; 12-16-2010 at 04:43 PM.
Reply With Quote
  #2  
Old 12-16-2010, 03:22 PM
snarfblam's Avatar
snarfblam snarfblam is offline
Senior Contributor

Forum Leader
* Expert *
 
Join Date: Apr 2005
Location: USA
Posts: 865
Default

It sounds like you want to show all checked items it TextBox1...

Why not clear TextBox1.Text first, then append any strings you want shown there.
Code:
' First you need to clear the text box (NOT SHOWN)
If CheckBox1.Checked Then
TextBox1.Text = TextBox1.Text & " / " & TextBox2.Text
If CheckBox2.Checked Then
TextBox1.Text = TextBox1.Text & " / " & TextBox3.Text
' and so on...
If you aren't familiar with the & operator, read all about it.

There are also two things I'm going to bother you about: First, you need better variable names, especially when you are asking other people to look at your code. "TextBox1" doesn't tell me anything about what the text box is for. It makes the code hard to read.

Second, please put code in [code] tags.
__________________
C# _VB.NET _
Reply With Quote
  #3  
Old 12-16-2010, 07:11 PM
s0mewhiteguy7 s0mewhiteguy7 is offline
Newcomer
 
Join Date: Dec 2010
Posts: 7
Default

Quote:
Originally Posted by snarfblam View Post
It sounds like you want to show all checked items it TextBox1...

Why not clear TextBox1.Text first, then append any strings you want shown there.
Code:
' First you need to clear the text box (NOT SHOWN)
If CheckBox1.Checked Then
TextBox1.Text = TextBox1.Text & " / " & TextBox2.Text
If CheckBox2.Checked Then
TextBox1.Text = TextBox1.Text & " / " & TextBox3.Text
' and so on...
how exactly would you clear TextBox1.Text......it starts clear bu then i try adding after every "If" TextBox1.Text = "" but when i do that then it just ends up do the same thing that i was already having problems with

This is aggrivating and I'm a newb (obviously )
Reply With Quote
  #4  
Old 12-16-2010, 07:22 PM
PlausiblyDamp's Avatar
PlausiblyDamp PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Wigan, UK
Posts: 1,676
Default

Do as snarfblam suggested and clear the textbox before you start comparing the checkboxes.
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
  #5  
Old 12-17-2010, 04:26 PM
snarfblam's Avatar
snarfblam snarfblam is offline
Senior Contributor

Forum Leader
* Expert *
 
Join Date: Apr 2005
Location: USA
Posts: 865
Default

I'm sorry...
Code:
' First you need to clear the text box (NOT SHOWN)
If CheckBox1.Checked Then
TextBox1.Text = TextBox1.Text & " / " & TextBox2.Text
If CheckBox2.Checked Then
TextBox1.Text = TextBox1.Text & " / " & TextBox3.Text
' and so on...
Should be
Code:
' First you need to clear the text box (NOT SHOWN)
If CheckBox1.Checked Then
    TextBox1.Text = TextBox1.Text & " / " & TextBox2.Text
End If
If CheckBox2.Checked Then
    TextBox1.Text = TextBox1.Text & " / " & TextBox3.Text
End If
' and so on...
__________________
C# _VB.NET _
Reply With Quote
Reply

Tags
aardvarks, adding, checkbox, text, textboxes, vague tags


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->