Advertisement
TermSpar

Calculator Code

Dec 9th, 2015
1,165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.94 KB | None | 0 0
  1. Public Class frmCalculator
  2.  
  3.     Private Sub btnEquals_Click(sender As System.Object, e As System.EventArgs) Handles btnEquals.Click
  4.         Dim num1 As String
  5.         Dim num2 As String
  6.         Dim op As String
  7.         Dim total As Integer 'or dim it to a double if you want decimals
  8.         num1 = txtCal.Text.Split(" ")(0)
  9.         num2 = txtCal.Text.Split(" ")(2)
  10.         op = txtCal.Text.Split(" ")(1)
  11.         Dim i As Double = Convert.ToDouble(num1)
  12.         Dim i2 As Double = Convert.ToDouble(num2)
  13.         If op = "+" Then
  14.             total = i + i2
  15.             txtCal.Text = total
  16.         ElseIf op = "-" Then
  17.             total = i - i2
  18.             txtCal.Text = total
  19.         ElseIf op = "*" Then
  20.             total = i * i2
  21.             txtCal.Text = total
  22.         ElseIf op = "/" Then
  23.             total = i / i2
  24.             txtCal.Text = total
  25.         End If
  26.  
  27.     End Sub
  28.  
  29.     Private Sub Button7_Click(sender As System.Object, e As System.EventArgs) Handles Button7.Click
  30.         txtCal.AppendText("1")
  31.     End Sub
  32.  
  33.     Private Sub Button8_Click(sender As System.Object, e As System.EventArgs) Handles Button8.Click
  34.         txtCal.AppendText("2")
  35.     End Sub
  36.  
  37.     Private Sub Button9_Click(sender As System.Object, e As System.EventArgs) Handles Button9.Click
  38.         txtCal.AppendText("3")
  39.     End Sub
  40.  
  41.     Private Sub Button4_Click(sender As System.Object, e As System.EventArgs) Handles Button4.Click
  42.         txtCal.AppendText("4")
  43.     End Sub
  44.  
  45.     Private Sub Button5_Click(sender As System.Object, e As System.EventArgs) Handles Button5.Click
  46.         txtCal.AppendText("5")
  47.     End Sub
  48.  
  49.     Private Sub Button6_Click(sender As System.Object, e As System.EventArgs) Handles Button6.Click
  50.         txtCal.AppendText("6")
  51.     End Sub
  52.  
  53.     Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
  54.         txtCal.AppendText("7")
  55.     End Sub
  56.  
  57.     Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
  58.         txtCal.AppendText("8")
  59.     End Sub
  60.  
  61.     Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
  62.         txtCal.AppendText("9")
  63.     End Sub
  64.  
  65.     Private Sub Button14_Click(sender As System.Object, e As System.EventArgs) Handles Button14.Click
  66.         txtCal.AppendText("0")
  67.     End Sub
  68.  
  69.     Private Sub Button10_Click(sender As System.Object, e As System.EventArgs) Handles Button10.Click
  70.         txtCal.AppendText(" + ")
  71.     End Sub
  72.  
  73.     Private Sub Button11_Click(sender As System.Object, e As System.EventArgs) Handles Button11.Click
  74.         txtCal.AppendText(" - ")
  75.     End Sub
  76.  
  77.     Private Sub Button12_Click(sender As System.Object, e As System.EventArgs) Handles Button12.Click
  78.         txtCal.AppendText(" * ")
  79.     End Sub
  80.  
  81.     Private Sub Button13_Click(sender As System.Object, e As System.EventArgs) Handles Button13.Click
  82.         txtCal.AppendText(" / ")
  83.     End Sub
  84. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement