Calculator VB Dot Net


Are you confused with the logic of designing a calculator and making it function exactly as you need then here is the exact code with designing many experienced programmers even may not get the logic behind calculator here is it for you guys. In this article i have posted the code as well attached the project files So that you wont be confused about designing.

About This code snippet:

This code snippet is the code for a basic calculator that i have developed in vb dot net platform. It does all the basic operation of a calculator.

Things to Know:

Before using the code or it might be confusing for many to understand the code immediately so i am explaining what i have done in designing.

I have 17 buttons in my designing number 0-9 for 10 buttons (, +,-,*,/) each of this operator takes a button and so its so its 4 total 14 buttons i have used for this then remaining three buttons (=,Clear,Close).

Code for calculator:



Public Class Form1
Dim operand1 As Double
Dim operand2 As Double
Dim [operator] As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox1.Text = TextBox1.Text & Button1.Text
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
TextBox1.Text = TextBox1.Text & Button2.Text
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
TextBox1.Text = TextBox1.Text & Button3.Text
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
TextBox1.Text = TextBox1.Text & Button4.Text
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
TextBox1.Text = TextBox1.Text & Button5.Text
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
TextBox1.Text = TextBox1.Text & Button6.Text
End Sub
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
TextBox1.Text = TextBox1.Text & Button7.Text
End Sub
Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
TextBox1.Text = TextBox1.Text & Button8.Text
End Sub
Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
TextBox1.Text = TextBox1.Text & Button9.Text
End Sub
Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
TextBox1.Text = TextBox1.Text & Button10.Text
End Sub
Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click
TextBox1.Text = ""
End Sub
Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
operand1 = Val(TextBox1.Text)
TextBox1.Text = ""
[operator] = "+"
End Sub
Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
operand2 = Val(TextBox1.Text)
Select Case [operator]
Case "+"
TextBox1.Text = operand1 + operand2
Case "-"
TextBox1.Text = operand1 - operand2
Case "*"
TextBox1.Text = operand1 * operand2
Case "/"
TextBox1.Text = operand1 / operand2
End Select
End Sub
Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click
operand1 = Val(TextBox1.Text)
TextBox1.Text = ""
[operator] = "-"
End Sub
Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click
operand1 = Val(TextBox1.Text)
TextBox1.Text = ""
[operator] = "*"
End Sub
Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click
Me.Close()
End Sub

Private Sub Button17_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button17.Click
operand1 = Val(TextBox1.Text)
TextBox1.Text = ""
[operator] = "/"
End Sub
End Class


Note:
Many will still have confusions about the button click handle so i have attached my project files of calculator with this download and use it.


Attachments

  • Calculator VB Dot Net (44446-224952-Calculator-VB-Dot-Net.rar)
  • Related Articles

    Object Serialisation in dot net

    This article provides an overview of the serialization used in Microsoft .NET and the usage of the same.For example, serialization is used to save session state in ASP.NET and to copy objects to the clipboard in Windows Forms. It is also used by remoting to pass objects by value from one application domain to another.

    More articles: Dot Net

    Comments

    No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: