Create an application in vb.net that perform live calculator using difference 10 digits buttons, 4 operators (+ , - , * , / ), put some scientific calculations facilities .
Public Class Form1
Dim no1, no2 As Double
Dim x As Integer
Dim op As Char
Dim b = False, c As Boolean = False
Dim d As Boolean = True
‘---------------------- 1-9 Buttons --------------------
Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click, Button8.Click, Button7.Click, Button6.Click, Button5.Click, Button4.Click, Button3.Click, Button2.Click, Button1.Click
If x = 1 Then
TextBox1.Clear()
x = 0
End If
b = True
If d = True Then
If Me.TextBox1.Text.IndexOf(".") = 1 Or Me.TextBox1.Text.IndexOf(".") = 0 Then
Me.TextBox1.Text += sender.text
Else
Me.TextBox1.Text = sender.text
d = False
End If
Else
Me.TextBox1.Text += sender.text
End If
End Sub
‘------------------- operators( +, - ,*, /) -----------------
Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click, Button15.Click, Button14.Click, Button13.Click
If c = True Then
no2 = Me.TextBox1.Text
Select Case op
Case "+"
Me.TextBox1.Text = no1 + no2
no1 = Me.TextBox1.Text
op = sender.text
Case "-"
Me.TextBox1.Text = no1 - no2
no1 = Me.TextBox1.Text
op = sender.text
Case "*"
Me.TextBox1.Text = no1 * no2
no1 = Me.TextBox1.Text
op = sender.text
Case "/"
Me.TextBox1.Text = no1 / no2
no1 = Me.TextBox1.Text
op = sender.text
End Select
d = True
Else
If x = 0 Then
no1 = Me.TextBox1.Text
op = sender.text
c = True
x = 1
End If
End If
End Sub
‘---------------------- (=) coding --------------------------
Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
If Me.TextBox1.Text = "" Then
Else
no2 = Me.TextBox1.Text
Select Case op
Case "+"
Me.TextBox1.Text = no1 + no2
Case "-"
Me.TextBox1.Text = no1 - no2
Case "*"
Me.TextBox1.Text = no1 * no2
Case "/"
Me.TextBox1.Text = no1 / no2
End Select
c = False
End If
End Sub
‘-------------------- point(.) -----------------------------
Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
If Me.TextBox1.Text.IndexOf(".") = -1 Then
Me.TextBox1.Text += Me.Button10.Text
End If
End Sub
‘----------------------- 0 Button --------------------------
Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
If Me.TextBox1.Text = "0" Then
Else
If b = False Then
Me.TextBox1.Text = Me.Button11.Text
Else
Me.TextBox1.Text += Me.Button11.Text
End If
End If
End Sub
‘---------------------- C ----------------------------
Private Sub Button23_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button23.Click
Me.TextBox1.Clear()
End Sub
‘----------------- sqrt button -----------------------
Private Sub Button17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button17.Click
Me.TextBox1.Text = Math.Sqrt(Me.TextBox1.Text)
End Sub
‘------------------- 1/X button ---------------------------
Private Sub Button19_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button19.Click
Me.TextBox1.Text = 1 / Me.TextBox1.Text
End Sub
‘-------------- BACKSPACE -----------------------------
Private Sub Button21_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button21.Click
Dim s As String
If Me.TextBox1.Text = "" Then
Else
s = Me.TextBox1.Text.Remove(Me.TextBox1.Text.Length - 1, 1)
Me.TextBox1.Text = s
c = False
End If
End Sub
‘----------------------- -/+ Button ---------------------------
Private Sub Button20_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button20.Click
Me.TextBox1.Text = -1 * Me.TextBox1.Tex
End Sub
‘----------------- CE -------------------------------
Private Sub Button22_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button22.Click
Me.TextBox1.Text = ""
no1 = Val("")
op = ""
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.TextBox1.Text = "0"
End Sub
‘----------------- sin --------------------------
Private Sub Button24_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button24.Click
Me.TextBox1.Text = Math.Sin(Me.TextBox1.Text)
End Sub
‘----------------- cos --------------------------
Private Sub Button25_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button25.Click
Me.TextBox1.Text = Math.Cos(Me.TextBox1.Text)
End Sub
‘----------------- tan --------------------------
Private Sub Button26_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button26.Click
Me.TextBox1.Text = Math.Tan(Me.TextBox1.Text)
End Sub
‘----------------- log --------------------------
Private Sub Button27_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button27.Click
Me.TextBox1.Text = Math.Log(Me.TextBox1.Text)
End Sub
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
e.Handled = True
End Sub
Made By: Yadav Roshani R. from Third Year of BCA
Comments
Post a Comment