Click here to Skip to main content
15,899,124 members
Home / Discussions / C#
   

C#

 
GeneralMessage Removed Pin
7-Feb-10 3:12
miggs707-Feb-10 3:12 
GeneralRe: Getting values to Add up from a datagrid text box [modified] Pin
OriginalGriff7-Feb-10 4:33
mveOriginalGriff7-Feb-10 4:33 
GeneralRe: Getting values to Add up from a datagrid text box Pin
miggs707-Feb-10 5:04
miggs707-Feb-10 5:04 
GeneralRe: Getting values to Add up from a datagrid text box Pin
OriginalGriff7-Feb-10 5:12
mveOriginalGriff7-Feb-10 5:12 
GeneralRe: Getting values to Add up from a datagrid text box Pin
miggs707-Feb-10 6:10
miggs707-Feb-10 6:10 
GeneralRe: Getting values to Add up from a datagrid text box Pin
OriginalGriff7-Feb-10 8:17
mveOriginalGriff7-Feb-10 8:17 
GeneralMessage Removed Pin
7-Feb-10 11:13
miggs707-Feb-10 11:13 
GeneralRe: Getting values to Add up from a datagrid text box Pin
OriginalGriff7-Feb-10 22:31
mveOriginalGriff7-Feb-10 22:31 
OK, rules for good code:
1) Don't use "#region" to break up your code, use it to group together similar items - consturctors, event handlers, public methods, private methods, and so on. If you want to show where you are handling comething, then extract it into a method, and give the method a sensible name "SingleC" and "DoubleC" for example. You can then comment these using "///" and intellisense will pick up and help you out. It makes the flow of control easier to spot. VS can extract code as a method, just highlight it and right click - "Refactor", "Extract Method"
2) Use indenting properly! VS indents things really nicely, and make it so much more obvious what it going on - I had to faff around a bit to get it like this (since I don't have and dont want) your class definitions but then VS indented everything really nicely.
3) Be consistant in indenting: one space, two space, back a bit - it really doesn't help you see what is going on. VS has loads of options for this: Indent braces to match content, number of character to indent, newlines, opening brace on same line, etc. Find a style you like, and stick with it. I prefer braces on new lines, indent three characters, indent braces to match content - but that is me, and there are enough arguments about that allready!
4) Don't use comments to explain what the code does - explain why the code is doing it. "This Sets If its a Single CEE or Double CEE" followed by a test saying "if (DBLCee == "False")" is useless - why is it important to know if it is single or double cee? I have no idea, and the comment does not help me at all. (P.S. I don't actually need to know, but someone who works on your code might).

double xVal = 0;

foreach (DataGridViewRow row in d_Endpost.Rows)
    {
    double postSpacing = 0.0;

    double postSpacingMetric = 0.0;
    string userEntry = (string)row.Cells["EPSpacing"].Value;
    if (!string.IsNullOrEmpty(userEntry))
        {
        if (Double.TryParse(userEntry, out postSpacing))
            {
            postSpacingMetric = I2M(postSpacing);
            }
        else
            {
            MessageBox.Show("Invalid entry (" + userEntry + ") please enter the post spacing in inches and try again");
            return;
            }
        xVal += postSpacingMetric;
        Console.WriteLine(xVal);
        }
    string PostType = row.Cells["EndPostType"].FormattedValue.ToString();
    string DBLCee = row.Cells["DBLCee"].FormattedValue.ToString();
    // This Sets If its a Single CEE or Double CEE
    // (Replace this comment with what a Single Cee and Double Cee are, and
    // why they are different.)
    if (DBLCee == "False")
        {
        SingleCee(Distance2Points, xVal, PostType);
        }
    else
        {
        DoubleCee(Distance2Points, xVal, PostType);
        }
    }
From this you can see a couple of things straight away:
1) All your processing code is outside the check to see if there is any data to process!
2) You have lest the Console.WriteLine in, when it serves no purpose now.

And the mthods became:
private void DoubleCee(double Distance2Points, double xVal, string PostType)
    {
    if (xVal < Distance2Points / 2)
        {
        ///This Figures the columns at the Left side of the Ridge
        ///This is the Left of the Double CEE
        Beam EndPost = new Beam();
        EndPost.StartPoint = new T3D.Point(xVal, 0, 0);
        EndPost.EndPoint = new T3D.Point(xVal, 0, (EaveHt - (PurlinSlope + I2M(1.5))) + (xVal * Math.Tan(AngleRadians)));
        EndPost.Material.MaterialString = "55";
        EndPost.Name = "Endpost";
        EndPost.Profile.ProfileString = PostType.ToString();
        EndPost.Position.Depth = Position.DepthEnum.BEHIND;
        EndPost.Position.Plane = Position.PlaneEnum.LEFT;
        EndPost.Position.Rotation = Position.RotationEnum.FRONT;
        EndPost.Class = "3";
        EndPost.Insert();
        ///This Figures the columns at the Left side of the Ridge
        ///This is the Right of the Double Cee
        Beam EndPostR = new Beam();
        EndPostR.StartPoint = new T3D.Point(xVal, 0, (EaveHt - (PurlinSlope + I2M(1.5))) + (xVal * Math.Tan(AngleRadians)));
        EndPostR.EndPoint = new T3D.Point(xVal, 0, 0);
        EndPostR.Material.MaterialString = "55";
        EndPostR.Name = "Endpost";
        EndPostR.Profile.ProfileString = PostType.ToString();
        EndPostR.Position.Depth = Position.DepthEnum.FRONT;
        EndPostR.Position.Plane = Position.PlaneEnum.LEFT;
        EndPostR.Position.Rotation = Position.RotationEnum.FRONT;
        EndPostR.Class = "3";
        EndPostR.Insert();
        }
    else
        {
        //This Figures the columns at the Right side of the Ridge
        ///This is the Left of the Double Cee
        Beam EndPost = new Beam();
        EndPost.StartPoint = new T3D.Point(xVal, 0, 0);
        EndPost.EndPoint = new T3D.Point(xVal, 0, (EaveHt - (PurlinSlope + I2M(1.5))) + ((Distance2Points - xVal) * Math.Tan(AngleRadians)));
        EndPost.Material.MaterialString = "55";
        EndPost.Name = "Endpost";
        EndPost.Profile.ProfileString = PostType.ToString();
        EndPost.Position.Depth = Position.DepthEnum.BEHIND;
        EndPost.Position.Plane = Position.PlaneEnum.LEFT;
        EndPost.Position.Rotation = Position.RotationEnum.BACK;
        EndPost.Class = "3";
        EndPost.Insert();
        ///This Figures the columns at the Right side of the Ridge
        ///This is the Right of the Double Cee
        Beam EndPostR = new Beam();
        EndPostR.StartPoint = new T3D.Point(xVal, 0, (EaveHt - (PurlinSlope + I2M(1.5))) + ((Distance2Points - xVal) * Math.Tan(AngleRadians)));
        EndPostR.EndPoint = new T3D.Point(xVal, 0, 0);
        EndPostR.Material.MaterialString = "55";
        EndPostR.Name = "EndPostR";
        EndPostR.Profile.ProfileString = PostType.ToString();
        EndPostR.Position.Depth = Position.DepthEnum.FRONT;
        EndPostR.Position.Plane = Position.PlaneEnum.LEFT;
        EndPostR.Position.Rotation = Position.RotationEnum.BACK;
        EndPostR.Class = "3";
        EndPostR.Insert();
        }
    }

private void SingleCee(double Distance2Points, double xVal, string PostType)
    {
    if (xVal < Distance2Points / 2)
        {
        ///This Figures the columns at the Left side of the Ridge
        Beam EndPost = new Beam();
        EndPost.StartPoint = new T3D.Point(xVal, 0, 0);
        EndPost.EndPoint = new T3D.Point(xVal, 0, (EaveHt - (PurlinSlope + I2M(1.5))) + (xVal * Math.Tan(AngleRadians)));
        EndPost.Material.MaterialString = "55";
        EndPost.Name = "Endpost";

        EndPost.Profile.ProfileString = PostType.ToString();
        EndPost.Position.Depth = Position.DepthEnum.MIDDLE;
        EndPost.Position.Plane = Position.PlaneEnum.LEFT;
        EndPost.Position.Rotation = Position.RotationEnum.FRONT;
        EndPost.Class = "3";
        EndPost.Insert();
        }
    else
        {
        ///This Figures the columns at the Right side of the Ridge
        Beam EndPost = new Beam();
        EndPost.StartPoint = new T3D.Point(xVal, 0, 0);

        EndPost.EndPoint = new T3D.Point(xVal, 0, (EaveHt - (PurlinSlope + I2M(1.5))) + ((Distance2Points - xVal) * Math.Tan(AngleRadians)));
        EndPost.Material.MaterialString = "55";
        EndPost.Name = "Endpost";
        EndPost.Profile.ProfileString = PostType.ToString();
        EndPost.Position.Depth = Position.DepthEnum.BEHIND;
        EndPost.Position.Plane = Position.PlaneEnum.LEFT;
        EndPost.Position.Rotation = Position.RotationEnum.BACK;
        EndPost.Class = "3";
        EndPost.Insert();
        }
    }
(I will leave it to you to comment them since I don't know that much about roofing houses!)
If Barbie is so popular, why do you have to buy her friends?

Eagles may soar, but weasels don't get sucked into jet engines.

If at first you don't succeed, destroy all evidence that you tried.

GeneralMessage Removed Pin
8-Feb-10 1:48
miggs708-Feb-10 1:48 
GeneralRe: Getting values to Add up from a datagrid text box Pin
OriginalGriff8-Feb-10 2:05
mveOriginalGriff8-Feb-10 2:05 
Questionoverlapping area of n ractangles Pin
hotthoughtguy6-Feb-10 10:41
hotthoughtguy6-Feb-10 10:41 
Questionchange resource file dynamically Pin
jojoba20106-Feb-10 7:19
jojoba20106-Feb-10 7:19 
AnswerRe: change resource file dynamically Pin
Richard MacCutchan6-Feb-10 9:23
mveRichard MacCutchan6-Feb-10 9:23 
QuestionResource+C# Pin
jojoba20106-Feb-10 5:45
jojoba20106-Feb-10 5:45 
AnswerRe: Resource+C# Pin
Richard MacCutchan6-Feb-10 9:20
mveRichard MacCutchan6-Feb-10 9:20 
Questionproblem with winform visual style in c# Pin
evanxg6-Feb-10 4:53
evanxg6-Feb-10 4:53 
QuestionChange A Property Within The Foreach Loop Pin
BlitzPackage6-Feb-10 3:54
BlitzPackage6-Feb-10 3:54 
AnswerRe: Change A Property Within The Foreach Loop Pin
OriginalGriff6-Feb-10 4:19
mveOriginalGriff6-Feb-10 4:19 
GeneralRe: Change A Property Within The Foreach Loop Pin
harold aptroot6-Feb-10 4:22
harold aptroot6-Feb-10 4:22 
GeneralRe: Change A Property Within The Foreach Loop Pin
OriginalGriff6-Feb-10 4:29
mveOriginalGriff6-Feb-10 4:29 
GeneralRe: Change A Property Within The Foreach Loop Pin
harold aptroot6-Feb-10 4:37
harold aptroot6-Feb-10 4:37 
AnswerRe: Change A Property Within The Foreach Loop Pin
BlitzPackage6-Feb-10 4:45
BlitzPackage6-Feb-10 4:45 
GeneralRe: Change A Property Within The Foreach Loop Pin
harold aptroot6-Feb-10 5:12
harold aptroot6-Feb-10 5:12 
AnswerRe: Change A Property Within The Foreach Loop Pin
#realJSOP6-Feb-10 5:44
professional#realJSOP6-Feb-10 5:44 
GeneralRe: Change A Property Within The Foreach Loop Pin
OriginalGriff6-Feb-10 9:00
mveOriginalGriff6-Feb-10 9:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.