Simple Calculator W/O Classes

Posts 1–12 of 12 · Page 1 of 1
Simple Calculator W/O Classes
Description:
Small, Light weight application which allows you to "Add, Subtract, Multiply, Divide".

My Usage: I Really Don't Know, I have made Better ones.



Required Items:
Window Form (Only 1 Form.)
3 Labels
4 Text-boxes
4 Buttons
1 Windows Form

Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            Dev_Pump.Text = "Made By: Dev_Pump";
            Dev_Pump.ReadOnly = true;
        }
        private void Addition_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Length == 0)
            {
                MessageBox.Show("You have not entered a number.");
            }
            else
            {
                //Calc values, Var
                int num1;
                int num2;
                float Answer;
                num1 = int.Parse(textBox1.Text);
                num2 = int.Parse(textBox2.Text);
                //Calc Add Start
                Answer = num1 + num2;
                textBox3.Text = Answer.ToString();
                SignL.Text = "+";
                ActionL.Text = "Action Used: Addition";
            }
        }

        private void Multiply_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Length == 0)
            {
                MessageBox.Show("You have not entered a number.");
            }
            else
            {
                //Calc values, Var
                int num1;
                int num2;
                float Answer;
                num1 = int.Parse(textBox1.Text);
                num2 = int.Parse(textBox2.Text);
                //Calc MultiP Start
                Answer = num1 * num2;
                textBox3.Text = Answer.ToString();
                SignL.Text = "X";
                ActionL.Text = "Action Used: Multiplcation";
            }
        }

        private void Subtract_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Length == 0)
            {
                MessageBox.Show("You have not entered a number.");
            }
            else
            {
                //Calc values, Var
                int num1;
                int num2;
                float Answer;
                num1 = int.Parse(textBox1.Text);
                num2 = int.Parse(textBox2.Text);
                //Calc SubT Start
                Answer = num1 - num2;
                textBox3.Text = Answer.ToString();
                SignL.Text = "-";
                ActionL.Text = "Action Used: Subtraction";
            }
        }

        private void Divide_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Length == 0)
            {
             MessageBox.Show("You have not entered a number.");
            }
                if (textBox1.Text.StartsWith ("0"))
                {
                    MessageBox.Show("WTF?.");
                }
                if (textBox2.Text.StartsWith("0"))
                {
                    MessageBox.Show("WTF?.");
                }
            else
            {
                //Calc values, Var
                int num1;
                int num2;
                float Answer;
                num1 = int.Parse(textBox1.Text);
                num2 = int.Parse(textBox2.Text);
                //Calc SubT Start
                Answer = num1 / num2;
                textBox3.Text = Answer.ToString();
                SignL.Text = "/";
                ActionL.Text = "Action Used: Division";
            }
        }
        private void TBox1(object sender, EventArgs e)
        {
            textBox1.Text = " ";
        }

        private void TBox2(object sender, EventArgs e)
        {
            textBox2.Text = " ";
        }
    }
}
Virus Total Scan
Calc.rarattachment deleted · 3 downloads before removal
I likes. Really good. Quick question: What is partial class? Is creating an object from it any different? And what's the point? Couldn't you just use a regular class? Just wondering. Please enlighten me
Quote Originally Posted by kronus980 View Post
I likes. Really good. Quick question: What is partial class? Is creating an object from it any different? And what's the point? Couldn't you just use a regular class? Just wondering. Please enlighten me
I can't really explain what a partial class is. I have not added any classes in the program, I will be releasing one with A Class or two.

The Following is what Microsoft Visual Studio 2010 automatically places in beginning of the program code.

Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
Oh okay. Thanks though. If you find out, post please.
you guys should really look to google such simple stuff, not even need to google.. just go on msdn.

Partial Class Definitions (C#)

i'm giving you the link because that will explain it to you better then i would (im not a great teacher)

edit:

Quote Originally Posted by zeco View Post
The partial keyword is used when the definition of a class is split over multiple source files. So basically then when you compile it, it combines all the different pieces of the class.
you forgot something important... on the same namespace... thats the point
Quote Originally Posted by 'Bruno View Post
you guys should really look to google such simple stuff, not even need to google.. just go on msdn.

Partial Class Definitions (C#)

i'm giving you the link because that will explain it to you better then i would (im not a great teacher)

edit:



you forgot something important... on the same namespace... thats the point
Well I had assumed that of course it would be the same namespace. . . Otherwise it wouldn't even be visible within scope, it just wouldn't make sense if it was a different namespace. . . .
Quote Originally Posted by zeco View Post
Well I had assumed that of course it would be the same namespace. . . Otherwise it wouldn't even be visible within scope, it just wouldn't make sense if it was a different namespace. . . .
but thats the whole point...
Quote Originally Posted by 'Bruno View Post
but thats the whole point...
Sidenote: In your sig you spelled beginner incorrectly.
Quote Originally Posted by zeco View Post
Sidenote: In your sig you spelled beginner incorrectly.
i dont see how useful is that for this topic... but thanks anyway.
Quote Originally Posted by 'Bruno View Post
i dont see how useful is that for this topic... but thanks anyway.
'Twasn't I'm just spammin' now.
you are completly off-topic. chat with pm
The partial keyword is used when the definition of a class is split over multiple source files. So basically then when you compile it, it combines all the different pieces of the class.
Posts 1–12 of 12 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us