Re: Newbie Advice/Critiscism
- From: "MikeD" <nobody@xxxxxxxxxxx>
- Date: Sat, 23 Jun 2007 07:20:08 -0400
"Argusy" <argusy@xxxxxxxxxxxxxxx> wrote in message
news:467CF968.6020103@xxxxxxxxxxxxxxxxxx
Darren (UK) wrote:
Hi Guys,<snip> - we don't need a repeat
OK this is my very first attempt at development and whilst it does what i
want it to i know that in actual the fact the coding is awful. The first
thing you will notice is the amount of repetition of similiar code that
does the same thing.
Im hoping that someone will take the time to look at the code and offer
some advice as to how to curtail the amount of lines of code. As it is
obvious to even the naivest coder there is some way of eliminating the
repetition. Im not asking for someone to rewrite the thing, what i am
after is someone to try explain the error of my ways and show me some
ways of cleaning the code up, as im sure that there will be occasions
where i will be able to apply lessons learnt.
Thanks
Darren
The coding is unfamiliar to me, so I guess this could be a "dotnet"
program, not classic VB.
All the same, you should look at creating arrays of checkboxes and
textboxes.
That is indeed VB.NET code. Assuming you mean control arrays, there's no
such thing in .NET. Instead, you have procedures handle events for multiple
controls. For example, these two event procedures:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
If TabControl1.SelectedTab.Name = "TabPage1" Then
CheckBox1.Checked = True
CheckBox2.Checked = True
CheckBox3.Checked = True
CheckBox4.Checked = True
CheckBox5.Checked = True
CheckBox6.Checked = True
CheckBox7.Checked = True
CheckBox8.Checked = True
CheckBox9.Checked = True
CheckBox10.Checked = True
CheckBox11.Checked = True
CheckBox12.Checked = True
CheckBox13.Checked = True
Else
CheckBox14.Checked = True
CheckBox15.Checked = True
CheckBox16.Checked = True
CheckBox17.Checked = True
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
If TabControl1.SelectedTab.Name = "TabPage1" Then
CheckBox1.Checked = False
CheckBox2.Checked = False
CheckBox3.Checked = False
CheckBox4.Checked = False
CheckBox5.Checked = False
CheckBox6.Checked = False
CheckBox7.Checked = False
CheckBox8.Checked = False
CheckBox9.Checked = False
CheckBox10.Checked = False
CheckBox11.Checked = False
CheckBox12.Checked = False
CheckBox13.Checked = False
Else
CheckBox14.Checked = False
CheckBox15.Checked = False
CheckBox16.Checked = False
CheckBox17.Checked = False
End If
End Sub
could be "combined" into a single event procedure like this:
Private Sub Button_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click, Button2.Click
If TabControl1.SelectedTab.Name = "TabPage1" Then
CheckBox1.Checked = False
CheckBox2.Checked = False
CheckBox3.Checked = False
CheckBox4.Checked = False
CheckBox5.Checked = False
CheckBox6.Checked = False
CheckBox7.Checked = False
CheckBox8.Checked = False
CheckBox9.Checked = False
CheckBox10.Checked = False
CheckBox11.Checked = False
CheckBox12.Checked = False
CheckBox13.Checked = False
Else
CheckBox14.Checked = False
CheckBox15.Checked = False
CheckBox16.Checked = False
CheckBox17.Checked = False
End If
End Sub
--
Mike
Microsoft MVP Visual Basic
.
- Follow-Ups:
- Re: Newbie Advice/Critiscism
- From: Argusy
- Re: Newbie Advice/Critiscism
- References:
- Newbie Advice/Critiscism
- From: Darren (UK)
- Re: Newbie Advice/Critiscism
- From: Argusy
- Newbie Advice/Critiscism
- Prev by Date: Re: Newbie Advice/Critiscism
- Next by Date: Re: Newbie Advice/Critiscism
- Previous by thread: Re: Newbie Advice/Critiscism
- Next by thread: Re: Newbie Advice/Critiscism
- Index(es):