Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

VB Calculator

By: a guest on Mar 15th, 2012  |  syntax: VB.NET  |  size: 8.72 KB  |  hits: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Public Class Form1
  2.  
  3.     Dim num1 As Double = Nothing
  4.     Dim num2 As Double = Nothing
  5.     Dim dec As Double = 0
  6.     Dim op As String = Nothing
  7.     Dim done As Boolean = False
  8.  
  9.     Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
  10.  
  11.     End Sub
  12.  
  13.     Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click
  14.         If done = True Then
  15.             num1 = 0
  16.             num2 = 0
  17.             dec = 0
  18.             op = Nothing
  19.             Label1.Text = num1
  20.             done = False
  21.         End If
  22.  
  23.         If dec <> 0 Then
  24.             num1 = num1 + (1 / 10 ^ dec)
  25.             dec = dec + 1
  26.         Else
  27.             num1 = num1 * 10 + 1
  28.             Label1.Text = num1
  29.  
  30.         End If
  31.         Label1.Text = num1
  32.     End Sub
  33.  
  34.     Private Sub btn2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn2.Click
  35.         If done = True Then
  36.             num1 = 0
  37.             num2 = 0
  38.             dec = 0
  39.             op = Nothing
  40.             Label1.Text = num1
  41.             done = False
  42.         End If
  43.  
  44.         If dec <> 0 Then
  45.             num1 = num1 + (2 / 10 ^ dec)
  46.             dec = dec + 1
  47.         Else
  48.             num1 = num1 * 10 + 2
  49.             Label1.Text = num1
  50.  
  51.         End If
  52.         Label1.Text = num1
  53.     End Sub
  54.  
  55.     Private Sub btn3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn3.Click
  56.         If done = True Then
  57.             num1 = 0
  58.             num2 = 0
  59.             dec = 0
  60.             op = Nothing
  61.             Label1.Text = num1
  62.             done = False
  63.         End If
  64.  
  65.         If dec <> 0 Then
  66.             num1 = num1 + (3 / 10 ^ dec)
  67.             dec = dec + 1
  68.         Else
  69.             num1 = num1 * 10 + 3
  70.             Label1.Text = num1
  71.  
  72.         End If
  73.         Label1.Text = num1
  74.     End Sub
  75.  
  76.     Private Sub btn4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn4.Click
  77.         If done = True Then
  78.             num1 = 0
  79.             num2 = 0
  80.             dec = 0
  81.             op = Nothing
  82.             Label1.Text = num1
  83.             done = False
  84.         End If
  85.  
  86.         If dec <> 0 Then
  87.             num1 = num1 + (4 / 10 ^ dec)
  88.             dec = dec + 1
  89.         Else
  90.             num1 = num1 * 10 + 4
  91.             Label1.Text = num1
  92.  
  93.         End If
  94.         Label1.Text = num1
  95.     End Sub
  96.  
  97.     Private Sub btn5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn5.Click
  98.         If done = True Then
  99.             num1 = 0
  100.             num2 = 0
  101.             dec = 0
  102.             op = Nothing
  103.             Label1.Text = num1
  104.             done = False
  105.         End If
  106.  
  107.         If dec <> 0 Then
  108.             num1 = num1 + (5 / 10 ^ dec)
  109.             dec = dec + 1
  110.         Else
  111.             num1 = num1 * 10 + 5
  112.             Label1.Text = num1
  113.  
  114.         End If
  115.         Label1.Text = num1
  116.     End Sub
  117.  
  118.     Private Sub btn6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn6.Click
  119.         If done = True Then
  120.             num1 = 0
  121.             num2 = 0
  122.             dec = 0
  123.             op = Nothing
  124.             Label1.Text = num1
  125.             done = False
  126.         End If
  127.  
  128.         If dec <> 0 Then
  129.             num1 = num1 + (6 / 10 ^ dec)
  130.             dec = dec + 1
  131.         Else
  132.             num1 = num1 * 10 + 6
  133.             Label1.Text = num1
  134.  
  135.         End If
  136.         Label1.Text = num1
  137.     End Sub
  138.  
  139.     Private Sub btn7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn7.Click
  140.         If done = True Then
  141.             num1 = 0
  142.             num2 = 0
  143.             dec = 0
  144.             op = Nothing
  145.             Label1.Text = num1
  146.             done = False
  147.         End If
  148.  
  149.         If dec <> 0 Then
  150.             num1 = num1 + (7 / 10 ^ dec)
  151.             dec = dec + 1
  152.         Else
  153.             num1 = num1 * 10 + 7
  154.             Label1.Text = num1
  155.  
  156.         End If
  157.         Label1.Text = num1
  158.     End Sub
  159.  
  160.     Private Sub btn8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn8.Click
  161.         If done = True Then
  162.             num1 = 0
  163.             num2 = 0
  164.             dec = 0
  165.             op = Nothing
  166.             Label1.Text = num1
  167.             done = False
  168.         End If
  169.  
  170.         If dec <> 0 Then
  171.             num1 = num1 + (8 / 10 ^ dec)
  172.             dec = dec + 1
  173.         Else
  174.             num1 = num1 * 10 + 8
  175.             Label1.Text = num1
  176.  
  177.         End If
  178.         Label1.Text = num1
  179.     End Sub
  180.  
  181.     Private Sub btn9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn9.Click
  182.         If done = True Then
  183.             num1 = 0
  184.             num2 = 0
  185.             dec = 0
  186.             op = Nothing
  187.             Label1.Text = num1
  188.             done = False
  189.         End If
  190.  
  191.         If dec <> 0 Then
  192.             num1 = num1 + (9 / 10 ^ dec)
  193.             dec = dec + 1
  194.         Else
  195.             num1 = num1 * 10 + 9
  196.             Label1.Text = num1
  197.  
  198.         End If
  199.         Label1.Text = num1
  200.     End Sub
  201.  
  202.     Private Sub btn0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn0.Click
  203.         If done = True Then
  204.             num1 = 0
  205.             num2 = 0
  206.             dec = 0
  207.             op = Nothing
  208.             Label1.Text = num1
  209.             done = False
  210.         End If
  211.  
  212.         If dec <> 0 Then
  213.             num1 = num1 + (0 / 10 ^ dec)
  214.             dec = dec + 1
  215.         Else
  216.             num1 = num1 * 10 + 0
  217.             Label1.Text = num1
  218.  
  219.         End If
  220.         Label1.Text = num1
  221.     End Sub
  222.  
  223.     Private Sub btnDec_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDec.Click
  224.         If dec = 0 Then
  225.             dec = 1
  226.         End If
  227.  
  228.     End Sub
  229.  
  230.     Private Sub btnC_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnC.Click
  231.         num1 = 0
  232.         num2 = 0
  233.         dec = 0
  234.         op = Nothing
  235.         Label1.Text = num1
  236.     End Sub
  237.  
  238.     Private Sub btnCE_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCE.Click
  239.         num1 = 0
  240.         dec = 0
  241.         Label1.Text = num1
  242.     End Sub
  243.  
  244.     Private Sub btnPlus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlus.Click
  245.         op = "Plus"
  246.         num2 = num1
  247.         num1 = 0
  248.         dec = 0
  249.         Label1.Text = num1
  250.     End Sub
  251.  
  252.     Private Sub btnMinus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMinus.Click
  253.         op = "Minus"
  254.         num2 = num1
  255.         num1 = 0
  256.         dec = 0
  257.         Label1.Text = num1
  258.     End Sub
  259.  
  260.     Private Sub btnMultiply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMultiply.Click
  261.         op = "Multiply"
  262.         num2 = num1
  263.         num1 = 0
  264.         dec = 0
  265.         Label1.Text = num1
  266.     End Sub
  267.  
  268.     Private Sub btnDivide_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDivide.Click
  269.         op = "Divide"
  270.         num2 = num1
  271.         num1 = 0
  272.         dec = 0
  273.         Label1.Text = num1
  274.     End Sub
  275.  
  276.     Private Sub btnPower_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPower.Click
  277.         op = "Power"
  278.         num2 = num1
  279.         num1 = 0
  280.         dec = 0
  281.         Label1.Text = num1
  282.     End Sub
  283.  
  284.     Private Sub btnRoot_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRoot.Click
  285.         op = "Root"
  286.         num2 = num1
  287.         num1 = 0
  288.         dec = 0
  289.         Label1.Text = num1
  290.     End Sub
  291.  
  292.     Private Sub btnEquals_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEquals.Click
  293.         Select Case op
  294.             Case "Plus"
  295.                 num1 = num2 + num1
  296.                 Label1.Text = num1
  297.             Case "Minus"
  298.                 num1 = num2 - num1
  299.                 Label1.Text = num1
  300.             Case "Multiply"
  301.                 num1 = num2 * num1
  302.                 Label1.Text = num1
  303.             Case "Divide"
  304.                 num1 = num2 / num1
  305.                 Label1.Text = num1
  306.             Case "Power"
  307.                 num1 = num2 ^ num1
  308.                 Label1.Text = num1
  309.             Case "Root"
  310.                 num1 = num2 ^ (1 / num1)
  311.                 Label1.Text = num1
  312.         End Select
  313.         done = True
  314.     End Sub
  315.  
  316.     Private Sub btnAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAbout.Click
  317.         MessageBox.Show("Created by Eric Newsom. To use the root symbol, type the number to be inside the root, hit the root symbol, and then what root you want to take the number to. For example, for 3√64, hit 64, then √, then 3. For the square root of 4, hit 4, then √, then 2.", "About")
  318.     End Sub
  319. End Class