Skip to main content

How to make a Calculator -(Part-4) of using Visual Basic2010


Calculator  - Visual Basic 2008 / 2010
Page 4
The Zero Button:
Double click on the zero button and add the following highlighted code:
Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click
If Button1.Text = Label1.Text Then
Button1.Text = "0."
ElseIf Button1.Text = "0." Then
Button1.Text = "0."
ElseIf Button1.Text = "0" Then
Button1.Text = "0."
ElseIf Button1.Text = Label3.Text Then
Button1.Text = "0."
Else
Button1.Text = Button1.Text & "0"
End If
End Sub

The Decimal Button:
Double click on the decimal button and add the following highlighted code:
Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click
If Button1.Text = "0." Then
Button1.Text = "."
ElseIf Button1.Text = Label3.Text Then
Button1.Text = "."
ElseIf Button1.Text = Label1.Text Then
Button1.Text = "."
Else
If Button1.Text.Contains(".") Then
Else
Button1.Text = Button1.Text & "."
End If

End If
End Sub
The One Button:
Double click on the one button and add the following highlighted code:
Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
If Button1.Text = Label1.Text Then
Button1.Text = "1"
ElseIf Button1.Text = "0." Then
Button1.Text = "1"
ElseIf Button1.Text = Label3.Text Then
Button1.Text = "1"
Else
Button1.Text = Button1.Text & "1"
End If
End Sub
The Two Button:
Double click on the two button and add the following highlighted code:
Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
If Button1.Text = Label1.Text Then
Button1.Text = "2"
ElseIf Button1.Text = "0." Then
Button1.Text = "2"
ElseIf Button1.Text = Label3.Text Then
Button1.Text = "2"
Else
Button1.Text = Button1.Text & "2"
End If
End Sub
The Three Button:
Double click on the three button and add the following highlighted code:
Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
If Button1.Text = Label1.Text Then
Button1.Text = "3"
ElseIf Button1.Text = "0." Then
Button1.Text = "3"
ElseIf Button1.Text = Label3.Text Then
Button1.Text = "3"
Else
Button1.Text = Button1.Text & "3"
End If
End Sub
The Four Button:
Double click on the four button and add the following highlighted code:
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
If Button1.Text = Label1.Text Then
Button1.Text = "4"
ElseIf Button1.Text = "0." Then
Button1.Text = "4"
ElseIf Button1.Text = Label3.Text Then
Button1.Text = "4"
Else
Button1.Text = Button1.Text & "4"
End If
End Sub

The Five Button:
Double click on the five button and add the following highlighted code:
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
If Button1.Text = Label1.Text Then
Button1.Text = "5"
ElseIf Button1.Text = "0." Then
Button1.Text = "5"
ElseIf Button1.Text = Label3.Text Then
Button1.Text = "5"
Else
Button1.Text = Button1.Text & "5"
End If
End Sub

The Six Button:
Double click on the six button and add the following highlighted code:
Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
If Button1.Text = Label1.Text Then
Button1.Text = "6"
ElseIf Button1.Text = "0." Then
Button1.Text = "6"
ElseIf Button1.Text = Label3.Text Then
Button1.Text = "6"
Else
Button1.Text = Button1.Text & "6"
End If
End Sub


The Seven Button:
Double click on the seven button and add the following highlighted code:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If Button1.Text = Label1.Text Then
Button1.Text = "7"
ElseIf Button1.Text = "0." Then
Button1.Text = "7"
ElseIf Button1.Text = Label3.Text Then
Button1.Text = "7"
Else
Button1.Text = Button1.Text & "7"
End If
End Sub

The Eight Button:
Double click on the eight button and add the following highlighted code:
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If Button1.Text = Label1.Text Then
Button1.Text = "8"
ElseIf Button1.Text = "0." Then
Button1.Text = "8"
ElseIf Button1.Text = Label3.Text Then
Button1.Text = "8"
Else
Button1.Text = Button1.Text & "8"
End If
End Sub

The Nine Button:
Double click on the nine button and add the following highlighted code:
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
If Button1.Text = Label1.Text Then
Button1.Text = "9"
ElseIf Button1.Text = "0." Then
Button1.Text = "9"
ElseIf Button1.Text = Label3.Text Then
Button1.Text = "9"
Else
Button1.Text = Button1.Text & "9"
End If
End Sub

The calculator is ready now and should work fine.
                       
                                           

If your calculator is working fine, you can publish it:

                                              





Comments

Popular posts from this blog

How to make a Calculator

Calculator  - Visual Basic 2008 / 2010 Part- 1 This tutorial will show you how to make a basic calculator: Click on Project next to Create:  Click on Windows Form Application, and name the project "Your name's Calculator" and then click Ok. You can change the form text to "your name's calculator". Click on the form and then go to properties window, then change the text property. You also need to disable the maximize control of the form. That's because you don't want the user to maximize the calculator. Go to the properties window, and change the maximize box property to False:   You also need to change the FormBorderStyle property to Fixed3D   Add a button to the form and place on top of the form:   You might be surprised of this button because we should have placed a text box instead. Well, this is the cool thing about Visual Basic 2008, you can use a button to display text and results. Now we have to change the button prope...

Professional WordPress

Professional WordPress: Design and Development, 2nd Edition Brad Williams, David Damstra, Hal Stern     WordPress is the most popular self-hosted open source website software in use today, and the latest version makes it even simpler to operate. Packed with real-world examples for load balancing and multiusers, this esteemed resource replaces some of the more basic material with more advanced content. Every single chapter has been reworked to provide the most current and proper methods for developing and designing in WordPress. Coverage of HTML5, CSS3, and JavaScript and new chapters on custom post types, custom taxonomies, Multisite, and extensions of themes bring the content of this book completely up-to-date and provides you with all you need to deploy successful WordPress sites.      

Professional WordPress Design and Development, 3rd Edition

Professional WordPress: Design and Development, 3rd Edition Brad Williams, David Damstra, Hal Stern ISBN: 978-1-118-98724-7 504 pages December 2014 Professional WordPress is the only WordPress book targeted to developers, with advanced content that exploits the full functionality of the most popular CMS in the world. Fully updated to align with WordPress 4.1, this edition has updated examples with all new screenshots, and full exploration of additional tasks made possible by the latest tools and features. You will gain insight into real projects that currently use WordPress as an application framework, as well as the basic usage and functionality of the system from a developer's perspective. The book's key features include detailed information and real-world examples that illustrate the concepts and techniques at work, plus code downloads and examples accessible through the companion website. Written by practicing WordPress developers, the c...