Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer
This is the forum to discuss the Wrox book Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer by Rod Stephens; ISBN: 9780470596906
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 13th, 2012, 01:46 AM
Authorized User
Points: 130, Level: 2
Points: 130, Level: 2 Points: 130, Level: 2 Points: 130, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2012
Location: Australia
Posts: 32
Thanks: 1
Thanked 0 Times in 0 Posts
Unhappy Lesson 13 - Try It...Seriously?

Where do I start. This try it is incredibly frustrating. There is code present in the downloaded file that isnt referred to at all in the book. For example, this code:
Code:
 private decimal GrandTotal = 0;
is not mentioned at all, yet I have to add to the grand total and display the new result (without having declared GrandTotal if you follow the book).

The problem (apart from lack of detail) is that in Form 1 in this code
Code:
//get new values
                ListViewItem lvi = itemsListView.Items.Add(frm.ItemName);
                lvi.SubItems.Add(frm.PriceEach.ToString("C"));
                lvi.SubItems.Add(frm.Quantity.ToString("C"));
                lvi.SubItems.Add(frm.TotalPrice.ToString("C"));
I get errors on ItemName, PriceEach, Quantity and TotalPrice even though I have declared them in the NewItemForm:

Code:
public Form1()
        {
            InitializeComponent();
        }
        public string ItemName;
        public decimal PriceEach, Quantity, TotalPrice;

        private void btnCalculate_Click(object sender, EventArgs e)
        {
            ItemName = tbxItem.Text;
            PriceEach = decimal.Parse(tbxPriceEach.Text);
            Quantity = decimal.Parse(tbxQuantity.Text);

            TotalPrice = PriceEach * Quantity;
            tbxTotalPrice.Text=TotalPrice.ToString("C");

            btnOK.Enabled = true;

        }
------------------
This code from the downloaded Lesson 13 Try it contains NumberStyles.Any. When i try to type it, Intellisense doesnt find such an item.

Code:
PriceEach = decimal.Parse(priceEachTextBox.Text, NumberStyles.Any);
I have no idea what is happening and am at my wits end. The book seems to be becoming less helpful as more and more it seems to assume a novice coder has the knowledge to complete something that isnt shown. I might move to the next chapter and live without chapter 13. I dont think it will be a problem.

Oh and one more thing, the book asks you to create the NewItemForm first when you actually want the main form (Form1) to load first. Fortunately the internet helped me work out how to change which form starts first so I didnt have to remake the form.
__________________
"These pretzels are making me thirsty"
  #2 (permalink)  
Old November 13th, 2012, 11:41 AM
Rod Stephens's Avatar
Wrox Author
Points: 3,166, Level: 23
Points: 3,166, Level: 23 Points: 3,166, Level: 23 Points: 3,166, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
Default

Hi MinusZero,

I'm sorry you're finding this TryIt frustrating. If you get stuck on something, like creating the first form, email me or post here and I'll try to get you going again as quickly as possible. (For example, when you needed to change the startup form.)

Sorry the instructions don't say to build the main form first. That is confusing. I think I was considering the dialog to be the more interesting part of this problem so I started with it first. (When I program, I sometimes do that. I would create the project, ignore the startup form for now, and create the dialog first.)

This is left over from previous examples.

Code:
ListViewItem lvi = itemsListView.Items.Add(frm.ItemName);
lvi.SubItems.Add(frm.PriceEach.ToString("C"));
lvi.SubItems.Add(frm.Quantity.ToString("C"));
lvi.SubItems.Add(frm.TotalPrice.ToString("C"));
The values in red are declared in the dialog. (This is the main reason I built the dialog first. This code can't work in the main form until the dialog is built.) On the top of page 170 it says to create those fields in the dialog form's code outside of any methods.

Because they are public and outside of the methods, the main form's code can access them if it has a variable that refers to a dialog form. In this case, frm refers to one of those forms so frm.PriceEach refers to the PriceEach field owned by that form.

Quote:
This code from the downloaded Lesson 13 Try it contains NumberStyles.Any. When i try to type it, Intellisense doesnt find such an item.
Sorry about that. It's used on page 136 but as System.Globalization.NumberStyles.Any. This example uses a "using System.Globalization" statement at the top so later it can use NumberStyles.Any without starting it with "System.Globalization."

Quote:
I have no idea what is happening and am at my wits end. The book seems to be becoming less helpful as more and more it seems to assume a novice coder has the knowledge to complete something that isnt shown. I might move to the next chapter and live without chapter 13. I dont think it will be a problem.
Again I'm sorry about that. The book does assume you know more as you progress but there do seem to be some things here that are a bit of a stretch.

Please email or post if you get stuck. The book should be challenging but it's not intended to be an exercise in pain and frustration.
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
  #3 (permalink)  
Old November 13th, 2012, 06:44 PM
Authorized User
Points: 130, Level: 2
Points: 130, Level: 2 Points: 130, Level: 2 Points: 130, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2012
Location: Australia
Posts: 32
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thanks for your reply, I will let you know if I run into more problems.
__________________
"These pretzels are making me thirsty"
  #4 (permalink)  
Old June 10th, 2013, 12:42 PM
Authorized User
Points: 179, Level: 3
Points: 179, Level: 3 Points: 179, Level: 3 Points: 179, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2013
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I had similar problems when trying to figure this one out.

One mistake was here:

lvi.SubItems.Add(frm.Quantity.ToString("C"));

Quantity is not a Currency format, so there should not be a "C" in the brackets.

Removing the C made the error messages go away.

Also, the "using Sytem Globalization stumped me, until I watched the video for this Lesson, which covered it better.
  #5 (permalink)  
Old June 10th, 2013, 02:17 PM
Rod Stephens's Avatar
Wrox Author
Points: 3,166, Level: 23
Points: 3,166, Level: 23 Points: 3,166, Level: 23 Points: 3,166, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
Default

Sorry about the "C" thing. I don't know why that would cause error messages, though. It should just display the value as currency.

Yes, you should look at the videos, particularly if you're stumped. There's only so much room for details in the book.
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
  #6 (permalink)  
Old June 10th, 2013, 02:42 PM
Authorized User
Points: 179, Level: 3
Points: 179, Level: 3 Points: 179, Level: 3 Points: 179, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2013
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Default

But "Quantity" is not Currency
  #7 (permalink)  
Old June 10th, 2013, 04:06 PM
Rod Stephens's Avatar
Wrox Author
Points: 3,166, Level: 23
Points: 3,166, Level: 23 Points: 3,166, Level: 23 Points: 3,166, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
Default

The C just means "format this value as currency." If the value is an integer, like 2, it should produce "$2.00" I didn't think it would produce a warning or error. (But maybe it does. I'm still not at a computer so can't verify.)
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Lesson 13 Exercise 3 1rf2aa3oa4tb BOOK: Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer 3 July 2nd, 2012 12:04 PM
Lesson 13 Try it error alawode BOOK: Knight's Microsoft Business Intelligence 24-Hour Trainer 4 January 27th, 2012 08:32 PM
Lesson 7 Joakim BOOK: Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer 1 November 30th, 2011 11:16 AM
Lesson 4 - Try It brookesmith BOOK: JavaScript 24-Hour Trainer 2 September 15th, 2011 05:40 PM
Lesson 13: Task weird output gbargsley BOOK: Knight's 24-Hour Trainer: Microsoft SQL Server 2008 Integration Services 0 August 3rd, 2011 11:07 AM



All times are GMT -4. The time now is 02:43 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.