Solved

lining up the values

Posted on 2011-03-22
4
225 Views
Last Modified: 2012-05-11
I seem to be very close to an answer but this is getting me.
Windows form - VS2010 - C#
The first problem is that I'm dealing with tabulated data in the wrong kind of control but I'm stuck for output options (3rd party)

I have to out a grid of info
that is basically an hourly rate * hours worked (for the purpose of the question I've kept the numbers basic)
The code shows what I have and the image shows what I'm trying to output
Problem being that I only want to have the start of each row show the x hrs/wk and need a new line after each dollar value has been outputted.
int hoursPerWeek, payRate;
            for (payRate = 5; payRate <= 10; payRate++)
            {
                for (hoursPerWeek = 10; hoursPerWeek <= 20; hoursPerWeek++)
                {
                    string prefix = hoursPerWeek + " hrs/week: ";
                    memo.AppendText(prefix);
                    prefix = "";
                    memo.AppendText((hoursPerWeek * payRate) + "\t\t");
                    if (payRate == 10)
                    {
                        memo.AppendText("\n");
                    }
                }

Open in new window

grid.gif
0
Comment
Question by:QPR
  • 3
4 Comments
 
LVL 29

Accepted Solution

by:
anarki_jimbel earned 500 total points
ID: 35195696
I tried this - see the code.

Output:


10 hrs/week:             50            60            70            80            90            100            
11 hrs/week:             55            66            77            88            99            110            
12 hrs/week:             60            72            84            96            108            120            
13 hrs/week:             65            78            91            104            117            130            
14 hrs/week:             70            84            98            112            126            140            
15 hrs/week:             75            90            105            120            135            150            
16 hrs/week:             80            96            112            128            144            160            
17 hrs/week:             85            102            119            136            153            170            
18 hrs/week:             90            108            126            144            162            180            
19 hrs/week:             95            114            133            152            171            190            
20 hrs/week:             100            120            140            160            180            200            

StringBuilder memo = new StringBuilder();
            int hoursPerWeek, payRate;
            for (hoursPerWeek = 10; hoursPerWeek <= 20; hoursPerWeek++) 
            {
                string prefix = hoursPerWeek + " hrs/week: "+ "\t\t";
                memo.Append(prefix);
                for(payRate = 5; payRate <= 10; payRate++)
                {
                    memo.Append((hoursPerWeek * payRate) + "\t\t");
                    if (payRate == 10)
                    {
                        memo.AppendLine( );
                    }
                }
            }
            System.Diagnostics.Debug.WriteLine(memo.ToString());

Open in new window

0
 
LVL 29

Expert Comment

by:anarki_jimbel
ID: 35195702
You may need some formatting if you want to align columns properly but this is a bit different story...
0
 
LVL 29

Expert Comment

by:anarki_jimbel
ID: 35195715
0
 
LVL 29

Author Closing Comment

by:QPR
ID: 35195767
perfect
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now