Visual Calculator 11-11-2012, 04:30 AM
#1
What you need;
Starting up;
The rest;
Add the following into Module.vb;
Add the following into Form1.vb;
How it should look when finished;
Design;
- 16 Buttons
- TextBox
Starting up;
- Add a "Module"
The rest;
- Label the 16 buttons as such;
- Button1 = "1"
- Button2 = "2"
- Button3 = "3"
- Button4 = "4"
- Button5 = "5"
- Button6 = "6"
- Button7 = "7"
- Button8 = "8"
- Button9 = "9"
- Button10 = "0"
- Button11 = "."
- Button12 = "Enter"
- Button13 = "+"
- Button14 = "-"
- Button15 = "*"
- Button16 = "/"
Add the following into Module.vb;
Code:
Module Module1
Sub ShowValue(ByVal Butt As Button)
Form1.TextBox1.Text = Form1.TextBox1.Text & Butt.Text
End Sub
Sub Arithmetic(ByVal Butt As Button)
Form1.Value1 = Val(Form1.TextBox1.Text)
Form1.Oper = Butt.Text
Form1.TextBox1.Text = ""
End Sub
Sub Calculate()
Select Case Form1.Oper
Case "+"
Form1.TextBox1.Text = Form1.Value1 + Val(Form1.TextBox1.Text)
Case "-"
Form1.TextBox1.Text = Form1.Value1 - Val(Form1.TextBox1.Text)
Case "*"
Form1.TextBox1.Text = Form1.Value1 * Val(Form1.TextBox1.Text)
Case "/"
Form1.TextBox1.Text = Form1.Value1 / Val(Form1.TextBox1.Text)
End Select
End Sub
End Module
Add the following into Form1.vb;
Code:
Public Class Form1
Public Value1 As Double
Public Oper As Char
Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
ShowValue(Button10)
End Sub
Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
TextBox1.Text = TextBox1.Text & "."
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
ShowValue(Button3)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
ShowValue(Button2)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ShowValue(Button1)
End Sub
Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
Calculate()
End Sub
Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click
Arithmetic(Button13)
End Sub
Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click
Arithmetic(Button14)
End Sub
Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click
Arithmetic(Button16)
End Sub
Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click
Arithmetic(Button15)
End Sub
Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
ShowValue(Button9)
End Sub
Private Sub Button8_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
ShowValue(Button8)
End Sub
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
ShowValue(Button7)
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
ShowValue(Button4)
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
ShowValue(Button5)
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
ShowValue(Button6)
End Sub
End Class
How it should look when finished;
Design;
![[Image: 2ZPSM.png]](http://i.imgur.com/2ZPSM.png)