Solved

lining up the values

Posted on 2011-03-22
4
226 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

943 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

1 Experts available now in Live!

Get 1:1 Help Now