Re: Newbie Advice/Critiscism
- From: Argusy <argusy@xxxxxxxxxxxxxxx>
- Date: Sat, 23 Jun 2007 20:13:52 +0930
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 way, a lot of your code becomes
for i = 1 to 34 (or whatever the range is that you're changing
CheckBox(i).checked = False 'or true - whatever you're setting up
next
that reduces the number of those lines to just 3, plus
Dim i as integer
somewhere near the sub opening
You also repeat a lot of textboxes that are the same in all the If.. elseif's
ie
TextBox14.Text = "0"
TextBox15.Text = "2"
TextBox16.Text = "3"
There are more, I just stopped looking for them
pull these out and insert them before the "If ..." line
I'm not sure how many textboxes are duplicated, but just those three lines are repeated four times ( twelve lines in all - reduces to just three)
I don't know about all those registry changes, but I guess someone will bob up and let you know more efficient ways of coding them, or direct you to a forum where you'd get a more knowledgeable response
Argusy
.
- Follow-Ups:
- Re: Newbie Advice/Critiscism
- From: MikeD
- Re: Newbie Advice/Critiscism
- References:
- Newbie Advice/Critiscism
- From: Darren (UK)
- Newbie Advice/Critiscism
- Prev by Date: VB6 menu events
- Next by Date: Re: Newbie Advice/Critiscism
- Previous by thread: Newbie Advice/Critiscism
- Next by thread: Re: Newbie Advice/Critiscism
- Index(es):
Relevant Pages
|