|
|
 |
BOOK: Beginning C# 3.0 : An Introduction to Object Oriented Programming ISBN: 978-0-470-26129-3
 | This is the forum to discuss the Wrox book Beginning C# 3.0 : An Introduction to Object Oriented Programming by Jack Purdum; ISBN: 9780470261293 |
|
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Beginning C# 3.0 : An Introduction to Object Oriented Programming ISBN: 978-0-470-26129-3 section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
|
 |

November 4th, 2009, 06:21 PM
|
|
Registered User
|
|
Join Date: Nov 2009
Location: Prague, CZ
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Error: Expected class, delegate, or interface struct
Hello,
I am new to programming and attemting to work my way through your course. I am working on chapter 3; Interger Division app,
I figured out why I was getting errors on the "private void" statements. I needed to add the calc code inside the last bracket.
Now the program compiles without errors, and looks great. It just does not work. I can enter values into poerand 1 and operand2 and I can click the calculate button. and nothing happens. Not even the exit button works. The code is "exact" as in the book.
Below is my code:
using System;
using System.Windows.Forms;
publicclassfrmMain : Form
{
privateLabel label2;
privateTextBox txtOperand1;
privateTextBox txtOperand2;
privateTextBox txtResult;
privateButton btnCalc;
privateButton btnExit;
privateButton btnClear;
privateLabel label1;
#region Windows Code
privatevoid InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.txtOperand1 = new System.Windows.Forms.TextBox();
this.txtOperand2 = new System.Windows.Forms.TextBox();
this.txtResult = new System.Windows.Forms.TextBox();
this.btnCalc = new System.Windows.Forms.Button();
this.btnExit = new System.Windows.Forms.Button();
this.btnClear = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.label1.Location = new System.Drawing.Point(32, 30);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(126, 15);
this.label1.TabIndex = 0;
this.label1.Text = " Enter first interger value:";
//
// label2
//
this.label2.AutoSize = true;
this.label2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.label2.Location = new System.Drawing.Point(17, 56);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(142, 15);
this.label2.TabIndex = 1;
this.label2.Text = "Enter second interger value:";
//
// txtOperand1
//
this.txtOperand1.Location = new System.Drawing.Point(183, 27);
this.txtOperand1.Name = "txtOperand1";
this.txtOperand1.Size = new System.Drawing.Size(100, 20);
this.txtOperand1.TabIndex = 2;
//
// txtOperand2
//
this.txtOperand2.Location = new System.Drawing.Point(183, 54);
this.txtOperand2.Name = "txtOperand2";
this.txtOperand2.Size = new System.Drawing.Size(100, 20);
this.txtOperand2.TabIndex = 3;
//
// txtResult
//
this.txtResult.Location = new System.Drawing.Point(28, 93);
this.txtResult.Name = "txtResult";
this.txtResult.Size = new System.Drawing.Size(244, 20);
this.txtResult.TabIndex = 4;
//
// btnCalc
//
this.btnCalc.Location = new System.Drawing.Point(28, 143);
this.btnCalc.Name = "btnCalc";
this.btnCalc.Size = new System.Drawing.Size(75, 23);
this.btnCalc.TabIndex = 5;
this.btnCalc.Text = "Calculate";
this.btnCalc.UseVisualStyleBackColor = true;
//
// btnExit
//
this.btnExit.Location = new System.Drawing.Point(196, 142);
this.btnExit.Name = "btnExit";
this.btnExit.Size = new System.Drawing.Size(75, 23);
this.btnExit.TabIndex = 6;
this.btnExit.Text = "Exit";
this.btnExit.UseVisualStyleBackColor = true;
//
// btnClear
//
this.btnClear.Location = new System.Drawing.Point(111, 202);
this.btnClear.Name = "btnClear";
this.btnClear.Size = new System.Drawing.Size(75, 23);
this.btnClear.TabIndex = 7;
this.btnClear.Text = "Clear";
this.btnClear.UseVisualStyleBackColor = true;
this.btnClear.Visible = false;
//
// frmMain
//
this.ClientSize = new System.Drawing.Size(292, 252);
this.Controls.Add(this.btnClear);
this.Controls.Add(this.btnExit);
this.Controls.Add(this.btnCalc);
this.Controls.Add(this.txtResult);
this.Controls.Add(this.txtOperand2);
this.Controls.Add(this.txtOperand1);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Name = "frmMain";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
public frmMain()
{
InitializeComponent();
}
publicstaticvoid Main()
{
frmMain main = newfrmMain();
Application.Run(main);
}
privatevoid btnCalc_Click(object sender, EventArgs e)
{
bool flag;
float operand1;
float operand2;
float answer;
// Input Step
// Check first input...
flag = float.TryParse(txtOperand1.Text, out operand1);
if (flag == false)
{
MessageBox.Show("Enter a whole number", "Input Error");
txtOperand1.Focus();
return;
}
// Check second input
flag = float.TryParse(txtOperand2.Text, out operand2);
if (flag == false)
{
MessageBox.Show("Enter a whole number", "Input Error");
txtOperand2.Focus();
return;
}
// Process Step
answer = operand1 / operand2;
// Display Step
txtResult.Text = operand1.ToString() + " divided by " +
operand2.ToString() +
" equals " + answer.ToString();
txtResult.Visible = true;
}
privatevoid btnExit_Click(object sender, EventArgs e)
{
Close();
}
}
Last edited by cashpot : November 5th, 2009 at 12:18 PM.
Reason: I added Help comments for clarity of question
|

November 5th, 2009, 04:21 PM
|
|
Registered User
|
|
Join Date: Nov 2009
Location: Prague, CZ
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Where did this code come from?
Hello Dr. Purdum,
My original problem was with the Interger Division prm in chap. 3. I got errors on compile. I figured out that I needed to add the books code before the last curly bracket at the end of the .cs file. Next, I had an issue of program compiling and not working, just looking pretty.
After grinding it out line by line and two program versions later I finally firgured out why I had no action on my program.
It seems that the Template file from chap. 2 creates a #region Windows Code section and it gets populated during the course of building the form ( I am guessing) Anyway, for some reason my application fails to add two lines of code in both the btnCalc section and the btnExit section. They are as follows:
this.btnCalc.Click += new System.EventHandler(this.btnCalc_Click); &
this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
I found this discrepency by going through your code line by line and compairing it to my code.
I am using Visual C# 2008 Express Edition with SP1.
If I am to complete your textbook course, I will need to know why my program fails to insert thee correct code into the templated area of the .cs file.
Thank you in advance for your help.
Best regards,
Christopher
__________________
The only things in your life that will change it are: the people you meet and the books that you read!
|

November 8th, 2009, 08:44 PM
|
|
Authorized User
|
|
Join Date: Sep 2008
Location: Indianapolis, IN, USA.
Posts: 80
Thanks: 0
Thanked 6 Times in 6 Posts
|
|
I'm away from my home on vacation, so I can't check for sure, but did you include the System references as suggested on page 37?
__________________
Jack Purdum, Ph.D.
Author: Beginning C# 3.0: Introduction to Object Oriented Programming (and 14 other programming texts)
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |