Re: Newbie Advice/Critiscism



Darren (UK) wrote:
Hi Guys,

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

<snip> - we don't need a repeat

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

.



Relevant Pages

  • Re: How to return a result of a SQL query within an Event Procedur
    ... repeat any pair of combinations from text boxes A and B ("alpha" and ... Case insensitive, so ALPHA = alpha. ... I think you're missing something, ... have redunant information in a pair of textboxes bound to a table. ...
    (microsoft.public.access.formscoding)
  • Re: enable/disable textbox based on a check box
    ... > I have a form with several textboxes and check boxes, ... The form disables ... > This is the coding I am using in the Click event of the HS_Diploma ... > Before Update and After update events for the check box to no avail, ...
    (microsoft.public.access.formscoding)
  • Re: My talk about Godel to the post-grads.
    ... bewteen his conception of arithmetic and the contemporary view. ... For otherwise, and I repeat, the proof on its own terms was a commonplace. ... Otherwise it would be called So_and_so coding. ... set theorey. ...
    (sci.logic)
  • Re: Adding controls at Runtime
    ... "Morten Wennevik" wrote: ... > Just create a TextBox, or ArrayList, and put all your TabPage TextBoxes in it. ... >> private void SomeOtherMethod() ... >>> Happy coding! ...
    (microsoft.public.dotnet.languages.csharp)
  • How to get value of repeat same id name text box item in web
    ... I am developing web page using asp.net with c# coding. ... I would like to know how can i get the value of repeat same id name text box item in my aspx web page. ... Warm regards, ...
    (microsoft.public.dotnet.languages.csharp)