in else if condition it throw error like
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0103: The name 'c' does not exist in the current context
Source Error:
| Line 83: } Line 84: Line 85: else if (c != 0) Line 86: { Line 87: int c = int.Parse(TextBox3.Text) + int.Parse(TextBox4.Text); |
Source File: d:\sample tools\retrievedata\Default.aspx.cs Line: 85
Show Detailed Compiler Output:
Show Complete Compilation Source:
my design
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
my coding
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
int a = int.Parse(TextBox1.Text);
int b = int.Parse(TextBox2.Text);
// int c = int.Parse(TextBox3.Text);
if (a == b)
{
int c = int.Parse(TextBox1.Text) - int.Parse(TextBox2.Text);
TextBox3.Text = Convert.ToString(c);
//Label1.Text = "balance is nill";
}
else if (a >= b)
{
int c = int.Parse(TextBox1.Text) - int.Parse(TextBox2.Text);
TextBox3.Text = Convert.ToString(c);
}
else if (a <= b)
{
// Label1.Text = "Stock is over";
int c = int.Parse(TextBox1.Text) - int.Parse(TextBox2.Text);
TextBox3.Text = Convert.ToString(c);
}
}
protected void TextBox4_TextChanged(object sender, EventArgs e)
{
int a = int.Parse(TextBox1.Text);
int b = int.Parse(TextBox2.Text);
// int c = int.Parse(TextBox3.Text);
if (a == b)
{
int c = int.Parse(TextBox1.Text) - int.Parse(TextBox2.Text);
c= int.Parse(TextBox3.Text) - int.Parse(TextBox4.Text);
TextBox3.Text = Convert.ToString(c);
//Label1.Text = "balance is nill";
}
else if (c != 0)
{
int c = int.Parse(TextBox3.Text) + int.Parse(TextBox4.Text);
TextBox3.Text = Convert.ToString(c);
}

sudipta sanyalPosted Apr 29, 2014, 5:07 AM
as per your your form design i thing you want to calculate the balance of item.
so for this your logic will be balance_item = total_purchase - (sales_item + return_item)
but u did like this balance_item = balance_item + return_item
so as per my coercion thing about your logic... is this perfect...
selvi subramanianPosted Apr 29, 2014, 3:45 AM
{
c = int.Parse(TextBox3.Text) + int.Parse(TextBox4.Text);
TextBox3.Text = Convert.ToString(c);
}
we declare as c is not = zero then y we declare as c=zero.
now also it throw error sir
Server Error in '/retrievedata' Application.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.Compiler Error Message: CS0136: A local variable named 'c' cannot be declared in this scope because it would give a different meaning to 'c', which is already used in a 'parent or current' scope to denote something else
Source Error:
Line 79: if (a == b) Line 80: { Line 81: int c = int.Parse(TextBox1.Text) - int.Parse(TextBox2.Text); Line 82: Line 83: TextBox3.Text = Convert.ToString(c);Source File: d:\sample tools\retrievedata\Default.aspx.cs Line: 81
Version Information: Microsoft .NET Framework Version:2.0.50727.4984; ASP.NET Version:2.0.50727.4971
sudipta sanyalPosted Apr 29, 2014, 3:38 AM
protected void Button1_Click(object sender, EventArgs e)
{
int a = int.Parse(TextBox1.Text);
int b = int.Parse(TextBox2.Text);
int c = 0;
if (a == b)
{
c = int.Parse(TextBox1.Text) - int.Parse(TextBox2.Text);
TextBox3.Text = Convert.ToString(c);
//Label1.Text = "balance is nill";
}
else if (a >= b)
{
c = int.Parse(TextBox1.Text) - int.Parse(TextBox2.Text);
TextBox3.Text = Convert.ToString(c);
}
else if (a <= b)
{
// Label1.Text = "Stock is over";
c = int.Parse(TextBox1.Text) - int.Parse(TextBox2.Text);
TextBox3.Text = Convert.ToString(c);
}
}
protected void TextBox4_TextChanged(object sender, EventArgs e)
{
int a = int.Parse(TextBox1.Text);
int b = int.Parse(TextBox2.Text);
int c = 0; ;
if (a == b)
{
c = int.Parse(TextBox1.Text) - int.Parse(TextBox2.Text);
c = int.Parse(TextBox3.Text) - int.Parse(TextBox4.Text);
TextBox3.Text = Convert.ToString(c);
//Label1.Text = "balance is nill";
}
else if (c != 0)
{
c = int.Parse(TextBox3.Text) + int.Parse(TextBox4.Text);
TextBox3.Text = Convert.ToString(c);
}
}
selvi subramanianPosted Apr 29, 2014, 3:25 AM
no sir its not working please check it again. it throw error. like
Server Error in '/retrievedata' Application.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.Compiler Error Message: CS0136: A local variable named 'c' cannot be declared in this scope because it would give a different meaning to 'c', which is already used in a 'parent or current' scope to denote something else
Source Error:
Source File: d:\sample tools\retrievedata\Default.aspx.cs Line: 28
Show Detailed Compiler Output:
Show Complete Compilation Source:
Version Information: Microsoft .NET Framework Version:2.0.50727.4984; ASP.NET Version:2.0.50727.4971
sudipta sanyalPosted Apr 29, 2014, 3:17 AM
int b = int.Parse(TextBox2.Text);
int c; //edit
if (a == b)
{
c = int.Parse(TextBox1.Text) - int.Parse(TextBox2.Text); //edit
TextBox3.Text = Convert.ToString(c);