p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 4th, 2009, 06:21 PM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 5%
Activity: 5% Activity: 5% Activity: 5%
 
Join Date: Nov 2009
Location: Prague, CZ
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to cashpot Send a message via Skype™ to cashpot
Default 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old November 5th, 2009, 04:21 PM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 5%
Activity: 5% Activity: 5% Activity: 5%
 
Join Date: Nov 2009
Location: Prague, CZ
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to cashpot Send a message via Skype™ to cashpot
Default 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!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old November 8th, 2009, 08:44 PM
Authorized User
Points: 317, Level: 6
Points: 317, Level: 6 Points: 317, Level: 6 Points: 317, Level: 6
Activity: 17%
Activity: 17% Activity: 17% Activity: 17%
 
Join Date: Sep 2008
Location: Indianapolis, IN, USA.
Posts: 80
Thanks: 0
Thanked 6 Times in 6 Posts
Default

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)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Main.java:88: 'class' or 'interface' expected samnachilomo Java Basics 1 December 13th, 2006 09:07 AM
class and struct variables are confusing webworldman C# 2 August 7th, 2006 04:42 AM
interface and abstract class sreenu.pocha C# 2 July 26th, 2006 08:18 AM
USER INTERFACE CLASS gmk51080 ASP.NET 1.1 0 November 29th, 2004 06:00 AM
denotes a 'field' where a 'class' was expected jdang67 C# 1 November 12th, 2004 03:39 PM



All times are GMT -4. The time now is 08:10 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc