Click here to Skip to main content
15,913,722 members
Home / Discussions / C#
   

C#

 
QuestionSimple power-up question Pin
Star0930-Apr-09 10:23
Star0930-Apr-09 10:23 
QuestionRe: Simple power-up question Pin
Christian Graus30-Apr-09 10:37
protectorChristian Graus30-Apr-09 10:37 
AnswerRe: Simple power-up question Pin
Member 103390730-Apr-09 10:41
Member 103390730-Apr-09 10:41 
GeneralRe: Simple power-up question Pin
Star0930-Apr-09 11:01
Star0930-Apr-09 11:01 
AnswerRe: Simple power-up question Pin
Dan Neely30-Apr-09 10:53
Dan Neely30-Apr-09 10:53 
GeneralRe: Simple power-up question Pin
Mycroft Holmes30-Apr-09 15:33
professionalMycroft Holmes30-Apr-09 15:33 
Questionhow to search Active Directory for locked out accounts? Pin
partialdata30-Apr-09 9:50
partialdata30-Apr-09 9:50 
QuestionType /Namespace error in code Pin
onetreeup30-Apr-09 9:23
onetreeup30-Apr-09 9:23 
I have code for a calculator, and continue to get an error that I cannot seem to find.

The error: The type or namespace name 'ArrayList' could not be found(are you missing a using directive or an assembly reference)

I have partial classes, delaring the following in the Calculator.Designer.cs

private string m_value;
private ArrayList m_store;

the rest of the code below is in the Calculator class:

Can someone see what might be missing?

Here is the code:

public partial class Calculator : Form
{

public Calculator()
{
InitializeComponent();
m_value = "";
m_store = new ArrayList();
}

private void btnSeven_Click(object sender, EventArgs e)
{
AddToArray(btnSeven);
}

private void btnEight_Click(object sender, EventArgs e)
{
AddToArray(btnEight);
}

private void btnNine_Click(object sender, EventArgs e)
{
AddToArray(btnNine);
}

private void btnFour_Click(object sender, EventArgs e)
{
AddToArray(btnFour);
}

private void btnFive_Click(object sender, EventArgs e)
{
AddToArray(btnFive);
}

private void btnSix_Click(object sender, EventArgs e)
{
AddToArray(btnSix);
}

private void btnOne_Click(object sender, EventArgs e)
{
AddToArray(btnOne);
}

private void btnTwo_Click(object sender, EventArgs e)
{
AddToArray(btnTwo);
}

private void btnThree_Click(object sender, EventArgs e)
{
AddToArray(btnThree);
}

private void btnZero_Click(object sender, EventArgs e)
{
AddToArray(btnZero);
}

//create method for array to calculate
private void AddToArray(Button btn)
{
//m_value this to set the value
m_value += btn.Text;

//set label lblResult = " to display it to user
lblResult.Text += btn.Text;

//make all enabled to use it
SetEnableOperatorBtns(true);

}

private void btnAdd_Click(object sender, EventArgs e)
{
AddOperatorToArray(btnAdd);
}

private void btnSubtract_Click(object sender, EventArgs e)
{
AddOperatorToArray(btnSubtract);
}

private void btnMultiply_Click(object sender, EventArgs e)
{
AddOperatorToArray(btnMultiply);
}

private void btnDivide_Click(object sender, EventArgs e)
{
AddOperatorToArray(btnDivide);
}

// Method to add the operator to the array
private void AddOperatorToArray(Button btn)
{
//add the value to the arrayList
m_store.Add(m_value);

//display the Result to user
lblResult.Text += btn.Text;

//make the value empty
m_value = "";

//add the opeator to arrayList
m_store.Add(btn.Text);

//make the decimal button enabled
btnDecimal.Enabled = true;

//call the SetEnableOperatorBtns(false); to make all operators unenabled
SetEnableOperatorBtns(false);
}

private void Reset()
{
m_value = "";
lblResult.Text = "";
m_store.Clear();
btnDecimal.Enabled = true;
}

private void SetEnableOperatorBtns(bool enable)
{
btnAdd.Enabled = enable;
btnSubtract.Enabled = enable;
btnMultiply.Enabled = enable;
btnDivide.Enabled = enable;
btnEquals.Enabled = enable;
}

private void btnDecimal_Click(object sender, EventArgs e)
{
//Add to arrayList
AddToArray(btnDecimal);
btnDecimal.Enabled = false;
}

//m_result here take the first element in m_store if this element is
//operator like +*-/, Exception gives us error else if will take the
//digits or dot point
private void btnEquals_Click(object sender, EventArgs e)
{
try
{
// add value to the arrayList
m_store.Add(m_value);
// add operator to the arrayList
m_store.Add(btnEquals.Text);
//take the first element in the array, make sure its a digit
//and then save it on m_result, else it will give exception
float.m_result = float.Parse(m_store[0].ToString());

//loop extracts all elements in arrayList then checks it
//if the element is operator it will calculate the prefix and
//postfix and give us the result

//for loop on arrayList and check for element if equal to opera or not
//if equal operator
for (int i = 0; i < m_value.Length; i++)
{
if(m_store[i].ToString() == "+")
{
lblResult.Text = "";
m_result += float.Parse(m_store[i+1].ToString());
lblResult.Text = m_result.ToString();
}
else
if(m_store[i].ToString() == "-")
{
lblResult.Text = "";
m_result -= float.Parse(m_store[i].ToString());
lblResult.Text = m_result.ToString();
}
else
if(m_store[i].ToString() == "*")
{
lblResult.Text = "";
m_result -= float.Parse(m_store[i].ToString());
lblResult.Text = m_result.ToString();
}
else
if(m_store[i].ToString() == "/")
{
lblResult.Text = "";
m_result -= float.Parse(m_store[i].ToString());
lblResult.Text = m_result.ToString();
}
}
m_store.Clear();
m_value = lblResult.Text;

for(int i=0; i < m_value.Length; i++)
{
if(m_value[i].ToString() == ".")
{
btnDecimal.Enabled = false;
break;
}
else
{
btnDecimal.Enabled = true;
}
}

btnEquals.Enabled = false;
}
catch(Exception exception)
{
MessageBox.Show(exception.Message, "Error");

}
}

private void btnClear_Click(object sender, EventArgs e)
{
Reset();
}
AnswerRe: Type /Namespace error in code Pin
S. Senthil Kumar30-Apr-09 9:29
S. Senthil Kumar30-Apr-09 9:29 
GeneralRe: Type /Namespace error in code Pin
onetreeup30-Apr-09 10:14
onetreeup30-Apr-09 10:14 
AnswerRe: Type /Namespace error in code Pin
Luc Pattyn30-Apr-09 9:33
sitebuilderLuc Pattyn30-Apr-09 9:33 
GeneralRe: Type /Namespace error in code Pin
onetreeup30-Apr-09 10:02
onetreeup30-Apr-09 10:02 
GeneralRe: Type /Namespace error in code Pin
Luc Pattyn30-Apr-09 10:12
sitebuilderLuc Pattyn30-Apr-09 10:12 
QuestionMatrix Inversion with C# Pin
Linda Woodard30-Apr-09 9:18
Linda Woodard30-Apr-09 9:18 
AnswerRe: Matrix Inversion with C# Pin
Luc Pattyn30-Apr-09 9:40
sitebuilderLuc Pattyn30-Apr-09 9:40 
AnswerRe: Matrix Inversion with C# Pin
Member 103390730-Apr-09 10:48
Member 103390730-Apr-09 10:48 
GeneralRe: Matrix Inversion with C# Pin
Linda Woodard30-Apr-09 11:18
Linda Woodard30-Apr-09 11:18 
GeneralRe: Matrix Inversion with C# Pin
Linda Woodard4-May-09 3:51
Linda Woodard4-May-09 3:51 
QuestionGel Button in Visual C#..... help needed Guys! Pin
Rajdeep.NET is BACK30-Apr-09 9:14
Rajdeep.NET is BACK30-Apr-09 9:14 
AnswerRe: Gel Button in Visual C#..... help needed Guys! Pin
ricmil4230-Apr-09 10:17
ricmil4230-Apr-09 10:17 
QuestionEmbed files in exe programmatically (pretty hard :( ) Pin
sodevrom30-Apr-09 8:39
sodevrom30-Apr-09 8:39 
AnswerRe: Embed files in exe programmatically (pretty hard :( ) Pin
Rajdeep.NET is BACK30-Apr-09 9:01
Rajdeep.NET is BACK30-Apr-09 9:01 
AnswerRe: Embed files in exe programmatically (pretty hard :( ) Pin
Giorgi Dalakishvili30-Apr-09 9:02
mentorGiorgi Dalakishvili30-Apr-09 9:02 
GeneralRe: Embed files in exe programmatically (pretty hard :( ) Pin
sodevrom30-Apr-09 9:06
sodevrom30-Apr-09 9:06 
AnswerRe: Embed files in exe programmatically (pretty hard :( ) Pin
Daniel Grunwald30-Apr-09 9:11
Daniel Grunwald30-Apr-09 9:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.