Wrox Programmer Forums
|
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 Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 25th, 2009, 07:14 AM
Registered User
 
Join Date: Feb 2009
Posts: 4
Thanks: 2
Thanked 0 Times in 0 Posts
Default The name 'txtOperande1' does not exist in the current context

Hi Dr Purdum,

I am a junior programmer looking to learn more about the .NET side of things, along with OOP methods, your book has been the bext book by far for an aspiring developer like myself.

Can you please help me with this.

I am currently working through PART 2, Chapter 3, Page 58 of your book.

I am working through the Integer Division problem, i have entered the code precisely, however i am constantly receiving the following error when trying to build the code.

"The name 'txtOperand1' does not exist in the current context"


where am i going wrong??????


Kindest Regards
Steve

p.s have pasted my code below




using System;
using System.Drawing;
using System.Windows.Forms;
publicclassfrmMain : Form
{
privateLabel int1input;
privateLabel label1;
privateTextBox textBox1;
privateTextBox textBox2;
privateButton btnCalc;
privateButton btnExit;
privateLabel label2;
#region Windows code
privatevoid InitializeComponent()
{
this.int1input = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.btnCalc = new System.Windows.Forms.Button();
this.btnExit = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// int1input
//
this.int1input.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.int1input.Location = new System.Drawing.Point(36, 42);
this.int1input.Name = "int1input";
this.int1input.Size = new System.Drawing.Size(152, 20);
this.int1input.TabIndex = 0;
this.int1input.Text = "Enter first integer value:";
this.int1input.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// label1
//
this.label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.label1.Location = new System.Drawing.Point(36, 76);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(152, 20);
this.label1.TabIndex = 1;
this.label1.Text = "Enter first second value:";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(216, 41);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(137, 20);
this.textBox1.TabIndex = 2;
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(216, 76);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(137, 20);
this.textBox2.TabIndex = 3;
//
// label2
//
this.label2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.label2.Location = new System.Drawing.Point(33, 131);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(320, 46);
this.label2.TabIndex = 4;
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// btnCalc
//
this.btnCalc.Location = new System.Drawing.Point(33, 210);
this.btnCalc.Name = "btnCalc";
this.btnCalc.Size = new System.Drawing.Size(129, 23);
this.btnCalc.TabIndex = 5;
this.btnCalc.Text = "&Calculate";
this.btnCalc.UseVisualStyleBackColor = true;
//
// btnExit
//
this.btnExit.Location = new System.Drawing.Point(224, 210);
this.btnExit.Name = "btnExit";
this.btnExit.Size = new System.Drawing.Size(129, 23);
this.btnExit.TabIndex = 6;
this.btnExit.Text = "&Exit";
this.btnExit.UseVisualStyleBackColor = true;
//
// frmMain
//
this.ClientSize = new System.Drawing.Size(390, 256);
this.Controls.Add(this.btnExit);
this.Controls.Add(this.btnCalc);
this.Controls.Add(this.label2);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.label1);
this.Controls.Add(this.int1input);
this.Name = "frmMain";
this.Load += new System.EventHandler(this.frmMain_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
public frmMain()
{
InitializeComponent();
}
publicstaticvoid Main()
{
frmMain main = newfrmMain();
Application.Run(main);
}
privatevoid frmMain_Load(object sender, EventArgs e)
{
}
privatevoid btnCalc_Click(object sender, EventArgs e)
{
bool flag;
int operand1;
int operand2;
int answer;

// Input Step
// Check first input....
flag = int.TryParse(txtoperand1.Text, out operand1);
if (flag == false)
{
MessageBox.Show("Enter a whole number", "Input Error");
txtOperand1.Focus();
return;
}

// Check second input...
flag = int.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 Exitbtn_Click(object sender, EventArgs e)
{
Close();
}


}
 
Old February 25th, 2009, 09:19 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Hello,
Based on your code it appears as though you have not named one of the textboxes txtOperand1, rather they are named as follows:

csharp Code:
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();

Based solely on the code you provided and without ever reading this manuscript my guess would be that textBox1 and textBox2 should be named: txtOperand1 && txtOperand2. This should clear up all of the errors you are having in your code.

FYI: Remember that C# is case sensitive. If you were to change the ID properties of the two textboxes as noted above, you are still going to recieve an error in your code here:

csharp Code:
flag = int.TryParse(txtoperand1.Text, out operand1);

Since txtoperand1 != txtOperand1.

hth.
-Doug
__________________
===============================================
Doug Parsons
Wrox online library: Wrox Books 24 x 7
Did someone here help you? Click on their post!
"Easy is the path to wisdom for those not blinded by themselves."
===============================================
The Following User Says Thank You to dparsons For This Useful Post:
stevemcd999 (February 25th, 2009)
 
Old February 25th, 2009, 06:55 PM
Registered User
 
Join Date: Feb 2009
Posts: 4
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Hi Doug,

Thank you for your very very quck response, your help was spot on.

Now working as it should, appeared as though i hit one of those "DOH!!" moments.

Thanks again
Steve
 
Old February 25th, 2009, 11:58 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

No problem Steve, glad it worked out for you!
__________________
===============================================
Doug Parsons
Wrox online library: Wrox Books 24 x 7
Did someone here help you? Click on their post!
"Easy is the path to wisdom for those not blinded by themselves."
===============================================





Similar Threads
Thread Thread Starter Forum Replies Last Post
Unable to set context in web.xml or context.xml. dchicks Apache Tomcat 1 March 7th, 2008 07:59 AM
Position of a node outside current context QuickSilver002 XSLT 2 April 19th, 2007 02:07 PM
Com context andris2000 VB Components 3 June 24th, 2004 08:57 AM
Force current rec on screen if errors exist wscheiman Access VBA 4 November 4th, 2003 02:39 PM
context help smukher Visual C++ 0 June 19th, 2003 08:09 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.