By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,276 Members | 1,410 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,276 IT Pros & Developers. It's quick & easy.

Murach's C# book, anyone used it?

P: n/a
I am an older person trying to learn C# just for the fun of it. I am a
veteran of older style languages (COBOL, FORTRAN, etc.) and I want to learn
an Object Orientated language. Currently working my way through Murach's C#
by Joel Murach and Doug Lowe. Since I am not taking a course, I have no one
to whom I can address questions. That is why I am turning to this
newsgroup. Is this the best NG for a newbie like me? Are there people out
there who have used the book?

My goal is not to bug the NG, as I am sure you all have many important
things to do with your time. I have progressed through the C# book through
Chapter 10. It is going exceedingly well. I am working all of the exercises
and trying to do everything the authors suggest. I ran into a problem with
Exercise 10-1. I would like to get into a general discussion about debugging
execution errors. More importantly, I would like to interact with people
who have experience with the book.

Here is my issue in brief that prompted me to join the NG: In Chapter 9 I
worked a program that created a method to do data validation called
IsValidData(). If a textbox contained invalid data, the method set the
focus to the offending textbox to give the user a chance to correct his
error. Following that statement the method executed: return false. The
exercise was working on a one form class. In Chapter 10 a similar program
worked on a class containing two forms, a main one called the Customer form
and a second one that is called named Payment form.

The program runs fine if you enter all of the information the way it
expects. If IsValidData() in the Payment form returns false, then
btnOK_Click() returns and throws and exception back in the Customer form.
What I expected to happen is the focus would be set to the offending field
(one of the three) and give the user a chance to correct his error. The
btnOK_Click() should not have left the Payment form before the user had a
chance fix the error. I am sure I have done something stupid as I did not
have this issue in Chapter 9.

I could provide a lot more information with code listings, but I am looking
for someone who has worked with the book. I need to understand how the code
interacts with the forms. It is the concept rather than the bug that
concerns me. Thank you for your help.

Robert Schuldenfrei

bo*@s-i-inc.com
Nov 16 '05 #1
Share this Question
Share on Google+
11 Replies


P: n/a
Robert,

See inline.

"Robert Schuldenfrei" <bo*@s-i-inc.com> wrote in message
news:WSktc.3038$eY2.1481@attbi_s02...
I am an older person trying to learn C# just for the fun of it. I am a
veteran of older style languages (COBOL, FORTRAN, etc.) and I want to learn an Object Orientated language. Currently working my way through Murach's C# by Joel Murach and Doug Lowe. Since I am not taking a course, I have no one to whom I can address questions. That is why I am turning to this
newsgroup. Is this the best NG for a newbie like me? Are there people out there who have used the book?
I have not used the book personally, but people in the newsgroup are
more than happy to answer whatever questions you have on C#/.NET, and well,
life in general.

My goal is not to bug the NG, as I am sure you all have many important
things to do with your time.


Apparently, I do not. Also, with the number of posts to this group per
day, I don't think that one or ten by you will be that much of an annoyance.
=)

As for the rest of your questions, it would help if you posted the code.
That way, we can see what is going on, and give you better advice. While
some of us might not have read the book, we can be of help still in helping
you to figure out the code.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
Nov 16 '05 #2

P: n/a
Hi Nick,

Thanks for the e.mail reply in addition to the reply to the NG. If I hear
from someone who has experience with the book, I will probably have a more
meaningful discussion without the need to post the code. You do raise a
very interesting point, however. If you are using an Integrated Development
Environment (IDE) the code and the graphical objects, like my two forms, are
not in one place or in the same form. One of the biggest problem for me is
just keeping track of where things are. In the old days, COBOL programs
were big, but they were all together in one place. In an IDE stuff is
spread out in graphic panes, on property sheets, in code, etc. I have not
yet developed a good feel for debugging yet in this environment. I am,
however, learning how to use the debugging windows of Auto, Local, and
Watch. This is my first baby steps into the wonderland of OO programming.

Thank you,

Bob

Robert Schuldenfrei

S. I. Inc.

32 Ridley Road

Dedham, MA 02026

(781) 329-4828

bo*@s-i-inc.com

www.s-i-inc.com

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:OU****************@tk2msftngp13.phx.gbl...
Robert,

See inline.

"Robert Schuldenfrei" <bo*@s-i-inc.com> wrote in message
news:WSktc.3038$eY2.1481@attbi_s02...
I am an older person trying to learn C# just for the fun of it. I am a
veteran of older style languages (COBOL, FORTRAN, etc.) and I want to learn
an Object Orientated language. Currently working my way through

Murach's C#
by Joel Murach and Doug Lowe. Since I am not taking a course, I have no one
to whom I can address questions. That is why I am turning to this
newsgroup. Is this the best NG for a newbie like me? Are there people

out
there who have used the book?


I have not used the book personally, but people in the newsgroup are
more than happy to answer whatever questions you have on C#/.NET, and

well, life in general.

My goal is not to bug the NG, as I am sure you all have many important
things to do with your time.
Apparently, I do not. Also, with the number of posts to this group

per day, I don't think that one or ten by you will be that much of an annoyance. =)

As for the rest of your questions, it would help if you posted the code. That way, we can see what is going on, and give you better advice. While
some of us might not have read the book, we can be of help still in helping you to figure out the code.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

Nov 16 '05 #3

P: n/a
Actually, the graphic layout and the code for a Windows Forms application
(which it sounds like you are writing) is all in the same place. In the IDE
you'll see a section labeled "Windows Form Designer generated code." If you
expand that section you'll see where all the controls are defined. I
recommend heeding the advice in the comments to not modify any of the code
in that section. Even if you are really careful and really know what you are
doing, it's still really difficult to predict how the IDE will react to
changes.

The property sheets and graphical interface are just different views into
your code. You might find it easier to get your head around C#/.Net by
starting with text only tools first, then moving into the IDE once you are
comfortable with the code the IDE uses under the hood to perform it's
graphical magic.

Colin

"Robert Schuldenfrei" <bo*@s-i-inc.com> wrote in message
news:DDltc.70065$gr.6768467@attbi_s52...
Hi Nick,

Thanks for the e.mail reply in addition to the reply to the NG. If I hear
from someone who has experience with the book, I will probably have a more
meaningful discussion without the need to post the code. You do raise a
very interesting point, however. If you are using an Integrated Development Environment (IDE) the code and the graphical objects, like my two forms, are not in one place or in the same form. One of the biggest problem for me is just keeping track of where things are. In the old days, COBOL programs
were big, but they were all together in one place. In an IDE stuff is
spread out in graphic panes, on property sheets, in code, etc. I have not
yet developed a good feel for debugging yet in this environment. I am,
however, learning how to use the debugging windows of Auto, Local, and
Watch. This is my first baby steps into the wonderland of OO programming.

Nov 16 '05 #4

P: n/a
I spend a lot of money on books. My peers and colleagues spend
a lot of money on books. Nobody I know would spend money on
this particular title. I've reveived the Murach book which is okay for
sitting around at Barnes & Noble as it has some minor value for issues
such as this or that that can be picked up from casual reading but if
you
want a meaningful introduction to OOP and the .NET Framework I
suggest using MCAD certification training guides 'and' textbooks from
Deitel and Deitel to help you learn C#.

Our Milwaukee Visual Studio Developers Group studied the available
texts and there was no argument: the MCAD Training Guides from
QUE written by Amit Kalani are outstanding. So are the Deitel and
Deitel text books.
QUE
http://www.pearson.ch/Default.aspx?pageid=42&d=1&i=12

Deitel & Deitel
http://www.deitel.com/

Books from those publishers used in conjunction with the MSDN
documentation should cover 80% of everything you'll need to learn.
Several other books regarding the theory and application of OOP
are out there discussing patterns, methodology and so on but I think
you'd agree you need to start with the ABC's.
--
<%= Clinton Gallagher
A/E/C Consulting, Web Design, e-Commerce Software Development
Wauwatosa, Milwaukee County, Wisconsin USA
NET csgallagher@ REMOVETHISTEXT metromilwaukee.com
URL http://www.metromilwaukee.com/clintongallagher/

"Robert Schuldenfrei" <bo*@s-i-inc.com> wrote in message
news:WSktc.3038$eY2.1481@attbi_s02...
I am an older person trying to learn C# just for the fun of it. I am a veteran of older style languages (COBOL, FORTRAN, etc.) and I want to learn an Object Orientated language. Currently working my way through Murach's C# by Joel Murach and Doug Lowe. Since I am not taking a course, I have no one to whom I can address questions. That is why I am turning to this
newsgroup. Is this the best NG for a newbie like me? Are there people out there who have used the book?

My goal is not to bug the NG, as I am sure you all have many important
things to do with your time. I have progressed through the C# book through Chapter 10. It is going exceedingly well. I am working all of the exercises and trying to do everything the authors suggest. I ran into a problem with Exercise 10-1. I would like to get into a general discussion about debugging execution errors. More importantly, I would like to interact with people who have experience with the book.

Here is my issue in brief that prompted me to join the NG: In Chapter 9 I worked a program that created a method to do data validation called
IsValidData(). If a textbox contained invalid data, the method set the focus to the offending textbox to give the user a chance to correct his error. Following that statement the method executed: return false. The exercise was working on a one form class. In Chapter 10 a similar program worked on a class containing two forms, a main one called the Customer form and a second one that is called named Payment form.

The program runs fine if you enter all of the information the way it
expects. If IsValidData() in the Payment form returns false, then
btnOK_Click() returns and throws and exception back in the Customer form. What I expected to happen is the focus would be set to the offending field (one of the three) and give the user a chance to correct his error. The btnOK_Click() should not have left the Payment form before the user had a chance fix the error. I am sure I have done something stupid as I did not have this issue in Chapter 9.

I could provide a lot more information with code listings, but I am looking for someone who has worked with the book. I need to understand how the code interacts with the forms. It is the concept rather than the bug that
concerns me. Thank you for your help.

Robert Schuldenfrei

bo*@s-i-inc.com

Nov 16 '05 #5

P: n/a
I forgot to add Andrew Troelsen's book [1] which won an award
as the best reference work of 2003.

-
<%= Clinton Gallagher
A/E/C Consulting, Web Design, e-Commerce Software Development
Wauwatosa, Milwaukee County, Wisconsin USA
NET csgallagher@ REMOVETHISTEXT metromilwaukee.com
URL http://www.metromilwaukee.com/clintongallagher/

[1] http://www.apress.com/book/bookDisplay.html?bID=19

"clintonG" <csgallagher@RE************@metromilwaukee.com> wrote in
message news:#n**************@TK2MSFTNGP10.phx.gbl...
I spend a lot of money on books. My peers and colleagues spend
a lot of money on books. Nobody I know would spend money on
this particular title. I've reveived the Murach book which is okay for
sitting around at Barnes & Noble as it has some minor value for issues
such as this or that that can be picked up from casual reading but if
you
want a meaningful introduction to OOP and the .NET Framework I
suggest using MCAD certification training guides 'and' textbooks from
Deitel and Deitel to help you learn C#.

Our Milwaukee Visual Studio Developers Group studied the available
texts and there was no argument: the MCAD Training Guides from
QUE written by Amit Kalani are outstanding. So are the Deitel and
Deitel text books.
QUE
http://www.pearson.ch/Default.aspx?pageid=42&d=1&i=12

Deitel & Deitel
http://www.deitel.com/

Books from those publishers used in conjunction with the MSDN
documentation should cover 80% of everything you'll need to learn.
Several other books regarding the theory and application of OOP
are out there discussing patterns, methodology and so on but I think
you'd agree you need to start with the ABC's.
--
<%= Clinton Gallagher
A/E/C Consulting, Web Design, e-Commerce Software Development
Wauwatosa, Milwaukee County, Wisconsin USA
NET csgallagher@ REMOVETHISTEXT metromilwaukee.com
URL http://www.metromilwaukee.com/clintongallagher/

"Robert Schuldenfrei" <bo*@s-i-inc.com> wrote in message
news:WSktc.3038$eY2.1481@attbi_s02...
I am an older person trying to learn C# just for the fun of it. I am
a
veteran of older style languages (COBOL, FORTRAN, etc.) and I want
to learn
an Object Orientated language. Currently working my way through Murach's C#
by Joel Murach and Doug Lowe. Since I am not taking a course, I

have no one
to whom I can address questions. That is why I am turning to this
newsgroup. Is this the best NG for a newbie like me? Are there people out
there who have used the book?

My goal is not to bug the NG, as I am sure you all have many

important things to do with your time. I have progressed through the C# book

through
Chapter 10. It is going exceedingly well. I am working all of the

exercises
and trying to do everything the authors suggest. I ran into a problem with
Exercise 10-1. I would like to get into a general discussion about debugging
execution errors. More importantly, I would like to interact with

people
who have experience with the book.

Here is my issue in brief that prompted me to join the NG: In

Chapter 9 I
worked a program that created a method to do data validation called
IsValidData(). If a textbox contained invalid data, the method set the
focus to the offending textbox to give the user a chance to correct

his
error. Following that statement the method executed: return false.

The
exercise was working on a one form class. In Chapter 10 a similar

program
worked on a class containing two forms, a main one called the

Customer form
and a second one that is called named Payment form.

The program runs fine if you enter all of the information the way it
expects. If IsValidData() in the Payment form returns false, then
btnOK_Click() returns and throws and exception back in the Customer form.
What I expected to happen is the focus would be set to the offending

field
(one of the three) and give the user a chance to correct his error.

The
btnOK_Click() should not have left the Payment form before the user

had a
chance fix the error. I am sure I have done something stupid as I

did not
have this issue in Chapter 9.

I could provide a lot more information with code listings, but I am

looking
for someone who has worked with the book. I need to understand how

the code
interacts with the forms. It is the concept rather than the bug

that concerns me. Thank you for your help.

Robert Schuldenfrei

bo*@s-i-inc.com


Nov 16 '05 #6

P: n/a
Hi Clinton,

Thanks for the information about Deitel and Deitel. I might look to a
certification training guide as my next step. For an introduction with
plenty of examples, Murach meets my needs. This is actually the second book
I have started. I got 245 pages into Sharp and Jagger, Microsoft VISUAL
C#.NET Step by Step. This book did nothing for me. I did not like the fact
that they had no student exercises. Their explanations of their own
examples were sketchy at best. Murach has a business applications focus and
that is where I come from. My interest is not in systems programming. Rest
easy that this will be only the first book I will work through. C# is going
to be a retirement project for me (at age 61 I am thinking about that), and
not a vehicle to make a living. Thanks for getting back to me and taking
time out to write of your experiences.

Cheers,

Bob

"clintonG" <csgallagher@RE************@metromilwaukee.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I spend a lot of money on books. My peers and colleagues spend
a lot of money on books. Nobody I know would spend money on
this particular title. I've reveived the Murach book which is okay for
sitting around at Barnes & Noble as it has some minor value for issues
such as this or that that can be picked up from casual reading but if
you want a meaningful introduction to OOP and the .NET Framework I
suggest using MCAD certification training guides 'and' textbooks from
Deitel and Deitel to help you learn C#.

Nov 16 '05 #7

P: n/a
Ah. As old farts over the hill I learn we have something in common.
All the more reason for you to start using certification training guides
and books from guys like Troelsen and the Deitels; who no longer
do the writing as they have student slaves ;-)

If your drawn to the case study books I would say the most popular
publisher has been WROX [1], a company that was recently acquired but
whose inventory is still available some of which went to APress [2]. My
book shelves are filled with red covers from WROX who also battles it
out for top spot with O'Reilly for Programmer's Reference Guides. I've
favored WROX for reference guides but only for presentation and
readability as both publishers are equals in technical scope. O'Reilly
has a fantasttic web site [3].

Whatever you think you are up to be advised that you should make
learning all you can about web services one of your priorities.

--
<%= Clinton Gallagher
A/E/C Consulting, Web Design, e-Commerce Software Development
Wauwatosa, Milwaukee County, Wisconsin USA
NET csgallagher@ REMOVETHISTEXT metromilwaukee.com
URL http://www.metromilwaukee.com/clintongallagher/

[1] http://www.wrox.com/
[2] http://www.apress.com/
[3] http://www.oreilly.com/


"Robert Schuldenfrei" <bo*@s-i-inc.com> wrote in message
news:NCrtc.4675$eY2.2856@attbi_s02...
Hi Clinton,

Thanks for the information about Deitel and Deitel. I might look to a
certification training guide as my next step. For an introduction with plenty of examples, Murach meets my needs. This is actually the second book I have started. I got 245 pages into Sharp and Jagger, Microsoft VISUAL C#.NET Step by Step. This book did nothing for me. I did not like the fact that they had no student exercises. Their explanations of their own
examples were sketchy at best. Murach has a business applications focus and that is where I come from. My interest is not in systems programming. Rest easy that this will be only the first book I will work through. C# is going to be a retirement project for me (at age 61 I am thinking about that), and not a vehicle to make a living. Thanks for getting back to me and taking time out to write of your experiences.

Cheers,

Bob

"clintonG" <csgallagher@RE************@metromilwaukee.com> wrote in message news:%2****************@TK2MSFTNGP10.phx.gbl...
I spend a lot of money on books. My peers and colleagues spend
a lot of money on books. Nobody I know would spend money on
this particular title. I've reveived the Murach book which is okay for sitting around at Barnes & Noble as it has some minor value for issues such as this or that that can be picked up from casual reading but if you want a meaningful introduction to OOP and the .NET Framework I
suggest using MCAD certification training guides 'and' textbooks from Deitel and Deitel to help you learn C#.


Nov 16 '05 #8

P: n/a
Hi Robert,

Thanks for posting in this group.

Yes, I am not reading this book either. I suggest you paste our your code
snippet for this issue. I think it should not be a big one. With the code,
the entire community can benefit, discuss and learn from it. :-)

Yes, using IDE, the surface is very complex, but the code is still reside
in .cs file, the design time view is just for efficiency and visual.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 16 '05 #9

P: n/a
OK, I give up! Here is the code listed below. This form is displayed from
an earlier form that had the following 2 statements:

Form paymentForm = new frmPayment();
DialogResults button = paymentForm.ShowDialog();

Here is the problem: If the user completes the frmPayment correctly, the
program works fine. If the user fails to enter a card number in
in the txtCardNumber.Text or does not make a selection from the expiration
date combo-boxes the program crashes. The purpose of
IsValidData() method is to test for these conditions, set the focus on the
offending object, and let the user make the correction. Instead,
my program leaves the form and returns to the original form, and dies
following the second statement above.

Thanks for any help you can give. Bob

-----------------------------------------------------------------------

using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

namespace Payment

{

/// <summary>

/// Summary description for frmPayment.

/// </summary>

public class frmPayment : System.Windows.Forms.Form

{

private System.Windows.Forms.GroupBox groupBox1;

private System.Windows.Forms.RadioButton rdoCreditCard;

private System.Windows.Forms.RadioButton rdoBillCustomer;

private System.Windows.Forms.ListBox lstCreditCardType;

private System.Windows.Forms.Label label1;

private System.Windows.Forms.TextBox txtCardNumber;

private System.Windows.Forms.Label label2;

private System.Windows.Forms.ComboBox cboExpirationYear;

private System.Windows.Forms.ComboBox cboExpirationMonth;

private System.Windows.Forms.Label label3;

private System.Windows.Forms.Button btnOK;

private System.Windows.Forms.Button btnCancel;

private System.Windows.Forms.CheckBox chkDefault;

/// <summary>

/// Required designer variable.

/// </summary>

private System.ComponentModel.Container components = null;

public frmPayment()

{

//

// Required for Windows Form Designer support

//

InitializeComponent();

//

// TODO: Add any constructor code after InitializeComponent call

//

}

/// <summary>

/// Clean up any resources being used.

/// </summary>

protected override void Dispose( bool disposing )

{

if( disposing )

{

if(components != null)

{

components.Dispose();

}

}

base.Dispose( disposing );

}

#region Windows Form Designer generated code

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

this.groupBox1 = new System.Windows.Forms.GroupBox();

this.rdoBillCustomer = new System.Windows.Forms.RadioButton();

this.rdoCreditCard = new System.Windows.Forms.RadioButton();

this.lstCreditCardType = new System.Windows.Forms.ListBox();

this.label1 = new System.Windows.Forms.Label();

this.txtCardNumber = new System.Windows.Forms.TextBox();

this.label2 = new System.Windows.Forms.Label();

this.cboExpirationYear = new System.Windows.Forms.ComboBox();

this.cboExpirationMonth = new System.Windows.Forms.ComboBox();

this.label3 = new System.Windows.Forms.Label();

this.btnOK = new System.Windows.Forms.Button();

this.btnCancel = new System.Windows.Forms.Button();

this.chkDefault = new System.Windows.Forms.CheckBox();

this.groupBox1.SuspendLayout();

this.SuspendLayout();

//

// groupBox1

//

this.groupBox1.Controls.Add(this.rdoBillCustomer);

this.groupBox1.Controls.Add(this.rdoCreditCard);

this.groupBox1.Location = new System.Drawing.Point(8, 16);

this.groupBox1.Name = "groupBox1";

this.groupBox1.Size = new System.Drawing.Size(280, 48);

this.groupBox1.TabIndex = 7;

this.groupBox1.TabStop = false;

this.groupBox1.Text = "Billing";

//

// rdoBillCustomer

//

this.rdoBillCustomer.Location = new System.Drawing.Point(144, 16);

this.rdoBillCustomer.Name = "rdoBillCustomer";

this.rdoBillCustomer.Size = new System.Drawing.Size(120, 24);

this.rdoBillCustomer.TabIndex = 1;

this.rdoBillCustomer.Text = "Bill customer";

this.rdoBillCustomer.CheckedChanged += new
System.EventHandler(this.Billing_CheckedChanged);

//

// rdoCreditCard

//

this.rdoCreditCard.Checked = true;

this.rdoCreditCard.Location = new System.Drawing.Point(16, 16);

this.rdoCreditCard.Name = "rdoCreditCard";

this.rdoCreditCard.TabIndex = 0;

this.rdoCreditCard.TabStop = true;

this.rdoCreditCard.Text = "Credit Card";

this.rdoCreditCard.CheckedChanged += new
System.EventHandler(this.Billing_CheckedChanged);

//

// lstCreditCardType

//

this.lstCreditCardType.Location = new System.Drawing.Point(152, 72);

this.lstCreditCardType.Name = "lstCreditCardType";

this.lstCreditCardType.Size = new System.Drawing.Size(120, 43);

this.lstCreditCardType.TabIndex = 0;

//

// label1

//

this.label1.Location = new System.Drawing.Point(8, 72);

this.label1.Name = "label1";

this.label1.TabIndex = 2;

this.label1.Text = "Credit card type:";

//

// txtCardNumber

//

this.txtCardNumber.Location = new System.Drawing.Point(152, 120);

this.txtCardNumber.Name = "txtCardNumber";

this.txtCardNumber.Size = new System.Drawing.Size(120, 20);

this.txtCardNumber.TabIndex = 1;

this.txtCardNumber.Text = "";

//

// label2

//

this.label2.Location = new System.Drawing.Point(8, 120);

this.label2.Name = "label2";

this.label2.TabIndex = 4;

this.label2.Text = "Card number:";

//

// cboExpirationYear

//

this.cboExpirationYear.DropDownStyle =
System.Windows.Forms.ComboBoxStyle.DropDownList;

this.cboExpirationYear.Location = new System.Drawing.Point(200, 144);

this.cboExpirationYear.Name = "cboExpirationYear";

this.cboExpirationYear.Size = new System.Drawing.Size(72, 21);

this.cboExpirationYear.TabIndex = 3;

//

// cboExpirationMonth

//

this.cboExpirationMonth.DropDownStyle =
System.Windows.Forms.ComboBoxStyle.DropDownList;

this.cboExpirationMonth.Location = new System.Drawing.Point(120, 144);

this.cboExpirationMonth.Name = "cboExpirationMonth";

this.cboExpirationMonth.Size = new System.Drawing.Size(72, 21);

this.cboExpirationMonth.TabIndex = 2;

//

// label3

//

this.label3.Location = new System.Drawing.Point(8, 148);

this.label3.Name = "label3";

this.label3.TabIndex = 7;

this.label3.Text = "Expiration date:";

//

// btnOK

//

this.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK;

this.btnOK.Location = new System.Drawing.Point(120, 208);

this.btnOK.Name = "btnOK";

this.btnOK.TabIndex = 5;

this.btnOK.Text = "OK";

this.btnOK.Click += new System.EventHandler(this.btnOK_Click);

//

// btnCancel

//

this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;

this.btnCancel.Location = new System.Drawing.Point(208, 208);

this.btnCancel.Name = "btnCancel";

this.btnCancel.TabIndex = 6;

this.btnCancel.Text = "Cancel";

this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);

//

// chkDefault

//

this.chkDefault.Checked = true;

this.chkDefault.CheckState = System.Windows.Forms.CheckState.Checked;

this.chkDefault.Location = new System.Drawing.Point(8, 176);

this.chkDefault.Name = "chkDefault";

this.chkDefault.Size = new System.Drawing.Size(184, 24);

this.chkDefault.TabIndex = 4;

this.chkDefault.Text = "Set as default billing method";

//

// frmPayment

//

this.AcceptButton = this.btnOK;

this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);

this.CancelButton = this.btnCancel;

this.ClientSize = new System.Drawing.Size(292, 266);

this.ControlBox = false;

this.Controls.Add(this.chkDefault);

this.Controls.Add(this.btnCancel);

this.Controls.Add(this.btnOK);

this.Controls.Add(this.label3);

this.Controls.Add(this.cboExpirationMonth);

this.Controls.Add(this.cboExpirationYear);

this.Controls.Add(this.label2);

this.Controls.Add(this.txtCardNumber);

this.Controls.Add(this.label1);

this.Controls.Add(this.lstCreditCardType);

this.Controls.Add(this.groupBox1);

this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;

this.MaximizeBox = false;

this.Name = "frmPayment";

this.Text = "Payment";

this.Load += new System.EventHandler(this.frmPayment_Load);

this.groupBox1.ResumeLayout(false);

this.ResumeLayout(false);

}

#endregion

private void frmPayment_Load(object sender, System.EventArgs e)

{

lstCreditCardType.Items.Add("VISA");

lstCreditCardType.Items.Add("Mastercard");

lstCreditCardType.Items.Add("American Express");

lstCreditCardType.SelectedIndex = 0; //default VISA

string[] months = {"Select a month...", //like BASIC data statement

"January", "February", "March", "April",

"May", "June", "July", "August", "September",

"October", "November", "December"};

foreach (string month in months) cboExpirationMonth.Items.Add(month); //List

cboExpirationMonth.SelectedIndex = 0; //default "Select a month..."

int year = DateTime.Today.Year; //pluck from structure Year property

int endYear = year + 8;

cboExpirationYear.Items.Add("Select a year..."); //List can be mixed type

while (year < endYear)

{

cboExpirationYear.Items.Add(year); //load the years

year++;

}

cboExpirationYear.SelectedIndex = 0; //default "Select a year..."

}

private void btnCancel_Click(object sender, System.EventArgs e)

{

//no code is given in text, but this just closes the form

this.Close();

}

private void btnOK_Click(object sender, System.EventArgs e)

{

if (IsValidData())

{

//Load text for the ListBox

string msg = null; //msg to be returned in the Tag

if (rdoCreditCard.Checked) //We are dealing with a credit card.

{

msg += "Charge to credit card." + "\n";

msg += "\n"; //data from list and combo boxes

msg += "Card type: " + lstCreditCardType.Text + "\n";

msg += "Card number: " + txtCardNumber.Text + "\n";

msg += "Expiration date: " + cboExpirationMonth.Text + "/"

+ cboExpirationYear.Text + "\n";

}

else //if it is not a credit card it must be direct billing

{

msg += "Send bill to customer." + "\n";

msg += "\n";

}

bool isDefaultBilling = chkDefault.Checked; //if checked add to msg

msg += "Default billing: " + isDefaultBilling;

this.Tag = msg; /*Notice that form is not a method so we can not

"return" anything. Information is PASSED through the Tag.*/

}

else

{

MessageBox.Show("Returned from Failure", "debug");

}

} /*Expected that if IsValidData() is false to see form at this point with

the focus set to the offending object*/

private bool IsValidData() //Necessary because first list item is
instructions

{

if (rdoCreditCard.Checked) //if not checking is unnessary

{

if (txtCardNumber.Text == "") //failure to enter card number

{

MessageBox.Show("You must enter a credit card number", "Entry error");

txtCardNumber.Focus();

return false;

}

if (cboExpirationMonth.SelectedIndex == 0) //month failure

{

MessageBox.Show("You must enter a month", "Entry error");

cboExpirationMonth.Focus();

return false;

}

if (cboExpirationYear.SelectedIndex == 0) //year failure

{

MessageBox.Show("You must enter a year", "Entry error");

cboExpirationYear.Focus();

return false;

}

}

return true;

}

private void Billing_CheckedChanged(object sender, System.EventArgs e)

{

//This method started out as rdoCreditCard_CheckedChange, but was

//changed to Billing_CheckedChanged. N.B.: You must also change the

//wiring in Form Designer Generated Code. This is how it looks now:

//this.rdoCreditCard.CheckedChanged +=

//new System.EventHandler(this.Billing_CheckedChanged);
if (rdoCreditCard.Checked) EnableControls();

else DisableControls();

}

private void EnableControls() //Credit card processing requires controls ON

{

lstCreditCardType.Enabled = true;

txtCardNumber.Enabled = true;

cboExpirationMonth.Enabled = true;

cboExpirationYear.Enabled = true;

}

private void DisableControls() //Bill customer grays out controls

{

lstCreditCardType.Enabled = false;

txtCardNumber.Enabled = false;

cboExpirationMonth.Enabled = false;

cboExpirationYear.Enabled = false;

}

}

}

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:OU****************@tk2msftngp13.phx.gbl...
Robert,

See inline.

"Robert Schuldenfrei" <bo*@s-i-inc.com> wrote in message
news:WSktc.3038$eY2.1481@attbi_s02...
I am an older person trying to learn C# just for the fun of it. I am a
veteran of older style languages (COBOL, FORTRAN, etc.) and I want to learn
an Object Orientated language. Currently working my way through

Murach's C#
by Joel Murach and Doug Lowe. Since I am not taking a course, I have no one
to whom I can address questions. That is why I am turning to this
newsgroup. Is this the best NG for a newbie like me? Are there people

out
there who have used the book?


I have not used the book personally, but people in the newsgroup are
more than happy to answer whatever questions you have on C#/.NET, and

well, life in general.

My goal is not to bug the NG, as I am sure you all have many important
things to do with your time.
Apparently, I do not. Also, with the number of posts to this group

per day, I don't think that one or ten by you will be that much of an annoyance. =)

As for the rest of your questions, it would help if you posted the code. That way, we can see what is going on, and give you better advice. While
some of us might not have read the book, we can be of help still in helping you to figure out the code.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

Nov 16 '05 #10

P: n/a
See what I was trying to tell you?

Take some good advice now. Get your head out of the case
study books and into the MCAD training guides and the language
textbooks. Do the excercises so you can learn your @ss from the
proverbial hole in the ground as OOP and the .NET Framework
are very different than procedural programming. :-)

--
<%= Clinton Gallagher
A/E/C Consulting, Web Design, e-Commerce Software Development
Wauwatosa, Milwaukee County, Wisconsin USA
NET csgallagher@ REMOVETHISTEXT metromilwaukee.com
URL http://www.metromilwaukee.com/clintongallagher/

"Robert Schuldenfrei" <bo*@s-i-inc.com> wrote in message
news:prItc.4946$4A6.3957@attbi_s52...
OK, I give up! Here is the code listed below. This form is displayed from an earlier form that had the following 2 statements:

Form paymentForm = new frmPayment();
DialogResults button = paymentForm.ShowDialog();

Here is the problem: If the user completes the frmPayment correctly, the program works fine. If the user fails to enter a card number in
in the txtCardNumber.Text or does not make a selection from the expiration date combo-boxes the program crashes. The purpose of
IsValidData() method is to test for these conditions, set the focus on the offending object, and let the user make the correction. Instead,
my program leaves the form and returns to the original form, and dies
following the second statement above.

Thanks for any help you can give. Bob

---------------------------------------------------------------------- -
using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

namespace Payment

{

/// <summary>

/// Summary description for frmPayment.

/// </summary>

public class frmPayment : System.Windows.Forms.Form

{

private System.Windows.Forms.GroupBox groupBox1;

private System.Windows.Forms.RadioButton rdoCreditCard;

private System.Windows.Forms.RadioButton rdoBillCustomer;

private System.Windows.Forms.ListBox lstCreditCardType;

private System.Windows.Forms.Label label1;

private System.Windows.Forms.TextBox txtCardNumber;

private System.Windows.Forms.Label label2;

private System.Windows.Forms.ComboBox cboExpirationYear;

private System.Windows.Forms.ComboBox cboExpirationMonth;

private System.Windows.Forms.Label label3;

private System.Windows.Forms.Button btnOK;

private System.Windows.Forms.Button btnCancel;

private System.Windows.Forms.CheckBox chkDefault;

/// <summary>

/// Required designer variable.

/// </summary>

private System.ComponentModel.Container components = null;

public frmPayment()

{

//

// Required for Windows Form Designer support

//

InitializeComponent();

//

// TODO: Add any constructor code after InitializeComponent call

//

}

/// <summary>

/// Clean up any resources being used.

/// </summary>

protected override void Dispose( bool disposing )

{

if( disposing )

{

if(components != null)

{

components.Dispose();

}

}

base.Dispose( disposing );

}

#region Windows Form Designer generated code

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

this.groupBox1 = new System.Windows.Forms.GroupBox();

this.rdoBillCustomer = new System.Windows.Forms.RadioButton();

this.rdoCreditCard = new System.Windows.Forms.RadioButton();

this.lstCreditCardType = new System.Windows.Forms.ListBox();

this.label1 = new System.Windows.Forms.Label();

this.txtCardNumber = new System.Windows.Forms.TextBox();

this.label2 = new System.Windows.Forms.Label();

this.cboExpirationYear = new System.Windows.Forms.ComboBox();

this.cboExpirationMonth = new System.Windows.Forms.ComboBox();

this.label3 = new System.Windows.Forms.Label();

this.btnOK = new System.Windows.Forms.Button();

this.btnCancel = new System.Windows.Forms.Button();

this.chkDefault = new System.Windows.Forms.CheckBox();

this.groupBox1.SuspendLayout();

this.SuspendLayout();

//

// groupBox1

//

this.groupBox1.Controls.Add(this.rdoBillCustomer);

this.groupBox1.Controls.Add(this.rdoCreditCard);

this.groupBox1.Location = new System.Drawing.Point(8, 16);

this.groupBox1.Name = "groupBox1";

this.groupBox1.Size = new System.Drawing.Size(280, 48);

this.groupBox1.TabIndex = 7;

this.groupBox1.TabStop = false;

this.groupBox1.Text = "Billing";

//

// rdoBillCustomer

//

this.rdoBillCustomer.Location = new System.Drawing.Point(144, 16);

this.rdoBillCustomer.Name = "rdoBillCustomer";

this.rdoBillCustomer.Size = new System.Drawing.Size(120, 24);

this.rdoBillCustomer.TabIndex = 1;

this.rdoBillCustomer.Text = "Bill customer";

this.rdoBillCustomer.CheckedChanged += new
System.EventHandler(this.Billing_CheckedChanged);

//

// rdoCreditCard

//

this.rdoCreditCard.Checked = true;

this.rdoCreditCard.Location = new System.Drawing.Point(16, 16);

this.rdoCreditCard.Name = "rdoCreditCard";

this.rdoCreditCard.TabIndex = 0;

this.rdoCreditCard.TabStop = true;

this.rdoCreditCard.Text = "Credit Card";

this.rdoCreditCard.CheckedChanged += new
System.EventHandler(this.Billing_CheckedChanged);

//

// lstCreditCardType

//

this.lstCreditCardType.Location = new System.Drawing.Point(152, 72);

this.lstCreditCardType.Name = "lstCreditCardType";

this.lstCreditCardType.Size = new System.Drawing.Size(120, 43);

this.lstCreditCardType.TabIndex = 0;

//

// label1

//

this.label1.Location = new System.Drawing.Point(8, 72);

this.label1.Name = "label1";

this.label1.TabIndex = 2;

this.label1.Text = "Credit card type:";

//

// txtCardNumber

//

this.txtCardNumber.Location = new System.Drawing.Point(152, 120);

this.txtCardNumber.Name = "txtCardNumber";

this.txtCardNumber.Size = new System.Drawing.Size(120, 20);

this.txtCardNumber.TabIndex = 1;

this.txtCardNumber.Text = "";

//

// label2

//

this.label2.Location = new System.Drawing.Point(8, 120);

this.label2.Name = "label2";

this.label2.TabIndex = 4;

this.label2.Text = "Card number:";

//

// cboExpirationYear

//

this.cboExpirationYear.DropDownStyle =
System.Windows.Forms.ComboBoxStyle.DropDownList;

this.cboExpirationYear.Location = new System.Drawing.Point(200, 144);

this.cboExpirationYear.Name = "cboExpirationYear";

this.cboExpirationYear.Size = new System.Drawing.Size(72, 21);

this.cboExpirationYear.TabIndex = 3;

//

// cboExpirationMonth

//

this.cboExpirationMonth.DropDownStyle =
System.Windows.Forms.ComboBoxStyle.DropDownList;

this.cboExpirationMonth.Location = new System.Drawing.Point(120, 144);

this.cboExpirationMonth.Name = "cboExpirationMonth";

this.cboExpirationMonth.Size = new System.Drawing.Size(72, 21);

this.cboExpirationMonth.TabIndex = 2;

//

// label3

//

this.label3.Location = new System.Drawing.Point(8, 148);

this.label3.Name = "label3";

this.label3.TabIndex = 7;

this.label3.Text = "Expiration date:";

//

// btnOK

//

this.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK;

this.btnOK.Location = new System.Drawing.Point(120, 208);

this.btnOK.Name = "btnOK";

this.btnOK.TabIndex = 5;

this.btnOK.Text = "OK";

this.btnOK.Click += new System.EventHandler(this.btnOK_Click);

//

// btnCancel

//

this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnCancel.Location = new System.Drawing.Point(208, 208);

this.btnCancel.Name = "btnCancel";

this.btnCancel.TabIndex = 6;

this.btnCancel.Text = "Cancel";

this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);

//

// chkDefault

//

this.chkDefault.Checked = true;

this.chkDefault.CheckState = System.Windows.Forms.CheckState.Checked;

this.chkDefault.Location = new System.Drawing.Point(8, 176);

this.chkDefault.Name = "chkDefault";

this.chkDefault.Size = new System.Drawing.Size(184, 24);

this.chkDefault.TabIndex = 4;

this.chkDefault.Text = "Set as default billing method";

//

// frmPayment

//

this.AcceptButton = this.btnOK;

this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);

this.CancelButton = this.btnCancel;

this.ClientSize = new System.Drawing.Size(292, 266);

this.ControlBox = false;

this.Controls.Add(this.chkDefault);

this.Controls.Add(this.btnCancel);

this.Controls.Add(this.btnOK);

this.Controls.Add(this.label3);

this.Controls.Add(this.cboExpirationMonth);

this.Controls.Add(this.cboExpirationYear);

this.Controls.Add(this.label2);

this.Controls.Add(this.txtCardNumber);

this.Controls.Add(this.label1);

this.Controls.Add(this.lstCreditCardType);

this.Controls.Add(this.groupBox1);

this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;

this.Name = "frmPayment";

this.Text = "Payment";

this.Load += new System.EventHandler(this.frmPayment_Load);

this.groupBox1.ResumeLayout(false);

this.ResumeLayout(false);

}

#endregion

private void frmPayment_Load(object sender, System.EventArgs e)

{

lstCreditCardType.Items.Add("VISA");

lstCreditCardType.Items.Add("Mastercard");

lstCreditCardType.Items.Add("American Express");

lstCreditCardType.SelectedIndex = 0; //default VISA

string[] months = {"Select a month...", //like BASIC data statement

"January", "February", "March", "April",

"May", "June", "July", "August", "September",

"October", "November", "December"};

foreach (string month in months) cboExpirationMonth.Items.Add(month); //List
cboExpirationMonth.SelectedIndex = 0; //default "Select a month..."

int year = DateTime.Today.Year; //pluck from structure Year property

int endYear = year + 8;

cboExpirationYear.Items.Add("Select a year..."); //List can be mixed type
while (year < endYear)

{

cboExpirationYear.Items.Add(year); //load the years

year++;

}

cboExpirationYear.SelectedIndex = 0; //default "Select a year..."

}

private void btnCancel_Click(object sender, System.EventArgs e)

{

//no code is given in text, but this just closes the form

this.Close();

}

private void btnOK_Click(object sender, System.EventArgs e)

{

if (IsValidData())

{

//Load text for the ListBox

string msg = null; //msg to be returned in the Tag

if (rdoCreditCard.Checked) //We are dealing with a credit card.

{

msg += "Charge to credit card." + "\n";

msg += "\n"; //data from list and combo boxes

msg += "Card type: " + lstCreditCardType.Text + "\n";

msg += "Card number: " + txtCardNumber.Text + "\n";

msg += "Expiration date: " + cboExpirationMonth.Text + "/"

+ cboExpirationYear.Text + "\n";

}

else //if it is not a credit card it must be direct billing

{

msg += "Send bill to customer." + "\n";

msg += "\n";

}

bool isDefaultBilling = chkDefault.Checked; //if checked add to msg

msg += "Default billing: " + isDefaultBilling;

this.Tag = msg; /*Notice that form is not a method so we can not

"return" anything. Information is PASSED through the Tag.*/

}

else

{

MessageBox.Show("Returned from Failure", "debug");

}

} /*Expected that if IsValidData() is false to see form at this point with
the focus set to the offending object*/

private bool IsValidData() //Necessary because first list item is
instructions

{

if (rdoCreditCard.Checked) //if not checking is unnessary

{

if (txtCardNumber.Text == "") //failure to enter card number

{

MessageBox.Show("You must enter a credit card number", "Entry error");

txtCardNumber.Focus();

return false;

}

if (cboExpirationMonth.SelectedIndex == 0) //month failure

{

MessageBox.Show("You must enter a month", "Entry error");

cboExpirationMonth.Focus();

return false;

}

if (cboExpirationYear.SelectedIndex == 0) //year failure

{

MessageBox.Show("You must enter a year", "Entry error");

cboExpirationYear.Focus();

return false;

}

}

return true;

}

private void Billing_CheckedChanged(object sender, System.EventArgs e)

{

//This method started out as rdoCreditCard_CheckedChange, but was

//changed to Billing_CheckedChanged. N.B.: You must also change the

//wiring in Form Designer Generated Code. This is how it looks now:

//this.rdoCreditCard.CheckedChanged +=

//new System.EventHandler(this.Billing_CheckedChanged);
if (rdoCreditCard.Checked) EnableControls();

else DisableControls();

}

private void EnableControls() //Credit card processing requires controls ON
{

lstCreditCardType.Enabled = true;

txtCardNumber.Enabled = true;

cboExpirationMonth.Enabled = true;

cboExpirationYear.Enabled = true;

}

private void DisableControls() //Bill customer grays out controls

{

lstCreditCardType.Enabled = false;

txtCardNumber.Enabled = false;

cboExpirationMonth.Enabled = false;

cboExpirationYear.Enabled = false;

}

}

}

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in message news:OU****************@tk2msftngp13.phx.gbl...
Robert,

See inline.

"Robert Schuldenfrei" <bo*@s-i-inc.com> wrote in message
news:WSktc.3038$eY2.1481@attbi_s02...
I am an older person trying to learn C# just for the fun of it. I am a veteran of older style languages (COBOL, FORTRAN, etc.) and I want to
learn
an Object Orientated language. Currently working my way through Murach's
C#
by Joel Murach and Doug Lowe. Since I am not taking a course, I
have no one
to whom I can address questions. That is why I am turning to this
newsgroup. Is this the best NG for a newbie like me? Are there
people out
there who have used the book?


I have not used the book personally, but people in the newsgroup are more than happy to answer whatever questions you have on C#/.NET, and well,
life in general.

My goal is not to bug the NG, as I am sure you all have many
important things to do with your time.


Apparently, I do not. Also, with the number of posts to this

group per
day, I don't think that one or ten by you will be that much of an annoyance.
=)

As for the rest of your questions, it would help if you posted

the code.
That way, we can see what is going on, and give you better advice.

While some of us might not have read the book, we can be of help still in

helping
you to figure out the code.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com


Nov 16 '05 #11

P: n/a
Dear Mr. Gallagher,

I solved the problem that caused my posting in the fist place. In order to
keep the method from returning I needed
to set the DialogResult property to None before the method call. If the
method had no issues I executed the following
statement just before returing:
this.DialogResult = DialogResult.OK;
If the above statement was not reached, as would be the case with a failure
to validate, the method does not return
and the offending textbox does indeed get focus.

As to your sagely advice below, I would kindly suggest that there is more
than one path to enlightenment. Rest easy
that I will get to the Deitel and Deitel book sometime during the summer.
Murach"s C# is working well for me now
and I am more than half way into it. I intend to complete that book and
rewrite some of my old ERP system (MCS-3)
in C#. Then I will proceed to probe Deitel and Deitel.

Thanks for your suggestions,

Bob
bo*@s-i-inc.com
www.s-i-inc.com
"clintonG" <csgallagher@RE************@metromilwaukee.com> wrote in message
news:OM**************@TK2MSFTNGP09.phx.gbl...
See what I was trying to tell you?

Take some good advice now. Get your head out of the case
study books and into the MCAD training guides and the language
textbooks. Do the excercises so you can learn your @ss from the
proverbial hole in the ground as OOP and the .NET Framework
are very different than procedural programming. :-)

--
<%= Clinton Gallagher
A/E/C Consulting, Web Design, e-Commerce Software Development
Wauwatosa, Milwaukee County, Wisconsin USA
NET csgallagher@ REMOVETHISTEXT metromilwaukee.com
URL http://www.metromilwaukee.com/clintongallagher/

Nov 16 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.