Guest User

Kalkulator

a guest
Feb 25th, 2023
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.50 KB | Source Code | 0 0
  1. namespace Kalkulator
  2. {
  3.     public partial class Form1 : Form
  4.     {
  5.         Double result = 0;
  6.         String operation = "";
  7.         bool isOperation = false;
  8.         public Form1()
  9.         {
  10.             InitializeComponent();
  11.         }
  12.  
  13.         private void Form1_Load(object sender, EventArgs e)
  14.         {
  15.  
  16.         }
  17.  
  18.         private void textBox1_TextChanged(object sender, EventArgs e)
  19.         {
  20.  
  21.         }
  22.  
  23.         private void button_Click(object sender, EventArgs e)
  24.         {
  25.             if ((textBox1.Text == "0") || (isOperation))
  26.                 textBox1.Clear();
  27.  
  28.             isOperation = false;
  29.             Button button = (Button)sender;
  30.             if (button.Text == ".")
  31.             {
  32.                 if (!textBox1.Text.Contains("."))
  33.                     textBox1.Text = textBox1.Text + button.Text;
  34.  
  35.             }
  36.             else
  37.                 textBox1.Text = textBox1.Text + button.Text;
  38.         }
  39.  
  40.         private void operator_Click(object sender, EventArgs e)
  41.         {
  42.             Button button = (Button)sender;
  43.             if (result != 0)
  44.             {
  45.                 button17.PerformClick();
  46.                 operation = button.Text;
  47.                 isOperation = true;
  48.             }
  49.             else
  50.             {
  51.                 operation = button.Text;
  52.                 result = Double.Parse(textBox1.Text);
  53.                 isOperation = true;
  54.             }
  55.         }
  56.  
  57.         private void button4_Click(object sender, EventArgs e)
  58.         {
  59.             textBox1.Text = "0";
  60.         }
  61.  
  62.         private void button18_Click(object sender, EventArgs e)
  63.         {
  64.             textBox1.Text = "0";
  65.             result = 0;
  66.         }
  67.  
  68.         private void button17_Click(object sender, EventArgs e)
  69.         {
  70.             switch (operation)
  71.             {
  72.                 case "+":
  73.                     textBox1.Text = (result + Double.Parse(textBox1.Text)).ToString();
  74.                     break;
  75.                 case "-":
  76.                     textBox1.Text = (result - Double.Parse(textBox1.Text)).ToString();
  77.                     break;
  78.                 case "*":
  79.                     textBox1.Text = (result * Double.Parse(textBox1.Text)).ToString();
  80.                     break;
  81.                 case "/":
  82.                     textBox1.Text = (result / Double.Parse(textBox1.Text)).ToString();
  83.                     break;
  84.                 default:
  85.                     break;
  86.             }
  87.             result = Double.Parse(textBox1.Text);
  88.         }
  89.     }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment