Solved

lining up the values

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

776 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