O'Reilly Forums: Ch3 Pg 113 - Joe And Bob Classes - O'Reilly Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Ch3 Pg 113 - Joe And Bob Classes Issue with class solution

#1 User is offline   Gildren 

  • Active Member
  • PipPip
  • Group: Members
  • Posts: 13
  • Joined: 20-September 13

Posted 16 December 2013 - 02:32 PM

In the code, the Messagebox.Show is supposed to be coded as:

"I don't have enough cash to give you " + amount, Name + " says ...");


Which I interpret to mean the window should say "I don't have enough cash to give you $5, Joe says ..."

However, when I run the program, the message I see is "I don't have enough cash to give you $5"

I'm not sure if I'm misunderstanding what's happening. I did notice the window says "Bob says ..." at the top, but I don't know if that's from another section or not.

FYI, there's a similar issue with the Messagebox.Show for
(amount + " isn't an amount I'll take", Name + " says ...")


Please clarify what the Messagebox should say. Thanks.
0

#2 User is offline   Rich Hopkins 

  • Active Member
  • PipPip
  • Group: Members
  • Posts: 11
  • Joined: 17-December 13

Posted 22 December 2013 - 04:42 PM

I think you have your page number wrong...

However, in a string such as the one you posted, the comma in "amount, Name" would break the string. Try changing it to amount + Name instead maybe? If that doesn't help, check the page number, because p113 is a Sharpen Your Pencil on methods.
0

#3 User is offline   FrontalMonk 

  • New Member
  • Pip
  • Group: Members
  • Posts: 6
  • Joined: 15-January 14

Posted 15 January 2014 - 01:19 PM

This is actually intentional. The Messagebox.Show method can take one or two parameters. the one you're thinking of is this:

MessageBox.Show("Foo");  //messagebox.show(string) displays a messagebox that has the string as its contents


And what you're using in this exercise is this:

MessageBox.Show("Foo", "This is a messagebox!");
//messagebox.show(string, string) displays a messagebox that has the first string as its contents, and the second as its header


So your code is doing the second one, taking two parameters for the messagebox.show method.
MessageBox.Show("I don't have enough cash to give you " + amount, Name + " says ...");  
//the comma after amount means the Name + " says ..." string is the second parameter the method is accepting


I hope that helps!
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users