CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    May 2000
    Location
    England
    Posts
    574

    Code review needed ......

    Hi,
    I have this huge if,else statement and i want to make it cleaner and use math to figure out
    but i can't seem to think how to do this
    can somebody cast an eye over this and tell me a nicer way of doing this ?


    Thanks

    Code:
    	if(nRed != 0 || nGreen != 0 || nBlue != 0)
    	{
    		brush1.CreateSolidBrush(RGB(nRed,nGreen,nBlue));
    		bColorShading = TRUE;
    	}
    	if (bColorShading == FALSE)
    	{
    		if (nTheShading <= 4)
    		{
    			strTheShading == "000";
    		}
    		else if (nTheShading >= 6 && nTheShading <= 9)
    		{
    			strTheShading == "005";
    		}
    		else if (nTheShading >= 11 && nTheShading <= 14)
    		{
    			strTheShading == "010";
    		}
    		else if (nTheShading >= 16 && nTheShading <= 19)
    		{
    			strTheShading == "015";
    		}
    		else if (nTheShading >= 21 && nTheShading <= 24)
    		{
    			strTheShading == "020";
    		}
    		else if (nTheShading >= 26 && nTheShading <= 29)
    		{
    			strTheShading == "025";
    		}
    		else if (nTheShading >= 31 && nTheShading <= 34)
    		{
    			strTheShading == "030";
    		}
    		else if (nTheShading >= 36 && nTheShading <= 39)
    		{
    			strTheShading == "035";
    		}
    		else if (nTheShading >= 41 && nTheShading <= 44)
    		{
    			strTheShading == "040";
    		}
    		else if (nTheShading >= 46  && nTheShading <= 49)
    		{
    			strTheShading == "045";
    		}
    		else if (nTheShading >= 51 && nTheShading <= 54)
    		{
    			strTheShading == "050";
    		}
    		else if (nTheShading >= 56 && nTheShading <= 59)
    		{
    			strTheShading == "055";
    		}
    		else if (nTheShading >= 61 && nTheShading <= 64)
    		{
    			strTheShading == "060";
    		}
    		else if (nTheShading >= 66 && nTheShading <= 69)
    		{
    			strTheShading == "065";
    		}
    		else if (nTheShading >= 71 && nTheShading <= 74)
    		{
    			strTheShading == "070";
    		}
    		else if (nTheShading >= 76 && nTheShading <= 79)
    		{
    			strTheShading == "075";
    		}
    		else if (nTheShading >= 81 && nTheShading <= 84)
    		{
    			strTheShading == "080";
    		}
    		else if (nTheShading >= 86 && nTheShading <= 89)
    		{
    			strTheShading == "085";
    		}
    		else if (nTheShading >= 91 && nTheShading <= 94)
    		{
    			strTheShading == "090";
    		}
    		else if (nTheShading >= 96 && nTheShading <= 99)
    		{
    			strTheShading == "095";
    		}
    		else if (nTheShading == 100)
    		{
    			strTheShading == "100";
    		}
    Any help would be appreciated

    Thank again

    P

  2. #2
    Join Date
    Oct 2002
    Location
    Singapore
    Posts
    3,128
    Code:
    int nValue = nTheShading / 5;
    
    if(nValue%5 != 0) // To exclude multiples of 5, just as in your code.
    {
        CString strTheShading;
    
        // I think you wanted to assign the value to strTheShading rather than comparsion.
        // Equivalent to: strTheShading = "00n"
        strTheShading.Format("%03d", (nValue-1) * 5);
    }

  3. #3
    Join Date
    May 2000
    Location
    England
    Posts
    574
    Thanks K
    I will learn and use this ....

    Have a good day

    P

  4. #4
    Join Date
    Oct 2002
    Location
    Singapore
    Posts
    3,128
    You're welcome.

  5. #5
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,867
    Another homework question answered...?
    "A problem well stated is a problem half solved.” - Charles F. Kettering

  6. #6
    Join Date
    May 2000
    Location
    England
    Posts
    574
    Wish it was homework ?

    Cheeky !!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured