Create Scientific Calculator Using Command Array VISUAL PROGRAMMING LAB

Friday, May 28, 2010

Step by step procedure: create the form for calculator using visual basic tool like command Button, Text button. Just like output screen .write the source code for appropriate object command box, text box, finally run the program. Create 30 command button 12 for numeric value 16 for scientific calculation and two for calculate off and on
Screen shot Output of the Calculator Using Command Array VISUAL PROGRAMMING LAB
Create Scientific Calculator Using Command Array Source CODE Visual programming Lap Scientific Caluculation

Dim str, a, choice As String
Dim num1, num2, num3, n2 As Double
Dim n, ans, b As Long
Private Sub Command1_Click(Index As Integer)
str = str + Command1(Index).Caption
Text1.Text = str
num2 = Val(str)
End Sub
Private Sub Command10_Click()
choice = "sqr"
str = ""
End Sub
Private Sub Command11_Click()
choice = "pow"
str = ""
End Sub
Private Sub Command12_Click()
choice = "inv"
str = ""
End Sub
Private Sub Command13_Click()
choice = "root"
str = ""
End Sub
Private Sub Command14_Click()
choice = "oct"
str = ""
End Sub
Private Sub Command15_Click()
choice = "e"
str = ""
End Sub
Private Sub Command16_Click()
choice = "e-"
str = ""
End Sub
Private Sub Command17_Click()
choice = "fact"
str = ""
End Sub
Private Sub Command18_Click()
choice = "cube"
str = ""
End Sub
Private Sub Command19_Click()
Text1.Text = ""
str = ""
End Sub
Private Sub Command2_Click(Index As Integer)
choice = Command2(Index).Caption
num1 = Val(Text1.Text)
Text1.Text = ""
str = ""
End Sub
Private Sub Command20_Click()
MsgBox "calculator Off"
Unload Form1
End Sub
Private Sub Command3_Click()
Select Case choice
Case "+"
num2 = Val(Text1.Text)
num2 = num2 + num1
Text1.Text = num2

Case "-"
num2 = Val(Text1.Text)
num2 = num1 - num2
Text1.Text = num2

Case "*"
num2 = Val(Text1.Text)
num2 = num2 * num1
Text1.Text = num2

Case "/"
num2 = Val(Text1.Text)
num2 = num1 / num2
Text1.Text = num2

Case "sin"
num2 = Math.Sin((num2 * 3.14) / 180)
Text1.Text = num2
str = " "

Case "cos"
num2 = Math.Cos((num2 * 3.14) / 180)
Text1.Text = num2
str = " "

Case "tan"
num2 = Math.Tan((num2 * 3.14) / 180)
Text1.Text = num2
str = " "

Case "sqr"
num2 = num2 * num2
Text1.Text = num2
str = " "

Case "cube"
num2 = num2 * num2 * num2
Text1.Text = num2
str = " "


Case "root"
num2 = num2 ^ (1 / 2)
Text1.Text = num2
str = " "

Case "log"
num2 = Math.Log(num2)
Text1.Text = num2
str = " "

Case "e"
num2 = Math.Exp(num2)
Text1.Text = num2
str = " "

Case "e-"
num2 = Math.Exp(-num2)
Text1.Text = num2
str = " "

Case "fact"
If (num2 < 2) Then
num2 = 1
Text1.Text = num2
str = " "
Else
num1 = 1
While (num2 > 1)
num1 = num1 * num2
num2 = num2 - 1
Wend
Text1.Text = num1
str = " "
End If

Case "bin"
n = num2
b = 1
ans = 0
str = ""
While (n > 0)
x = n Mod 2
n = (n - x) / 2
ans = ans + (b * x)
b = b * 10
Wend
Text1.Text = ans
str = " "

Case "oct"
n = num2
b = 1
ans = 0
str = " "
While (n > 0)
x = n Mod 8
n = (n - x) / 8
ans = ans + (b * x)
b = b * 10
Wend
Text1.Text = ans
str = " "

Case "hex"
n = num2
b = 1
ans = 0
str = " "
While (n > 0)
x = n Mod 16
n = (n - x) / 16
Select Case x
Case 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
s = x
str = Val(str) + Val(s)
Case 10
s = "A"
str = str + s
Case 11
s = "B"
str = str + s
Case 12
s = "C"
str = str + s
Case 13
s = "D"
str = str + s
Case 14
s = "E"
str = str + s
Case 15
s = "F"
str = str + s
End Select
Wend
Text1.Text = str
str = " "
Case "inv"
num2 = 1 / num2
Text1.Text = num2
str = " "
End Select
End Sub

Private Sub Command4_Click()
choice = "sin"
str = ""
End Sub

Private Sub Command5_Click()
choice = "cos"
str = ""
End Sub

Private Sub Command6_Click()
choice = "tan"
str = ""
End Sub

Private Sub Command7_Click()
choice = "log"
str = ""
End Sub

Private Sub Command8_Click()
choice = "bin"
str = ""
End Sub

Private Sub Command9_Click()
choice = "hex"
str = ""
End Sub
 

Result
Thus the calculator using command array was created successfully


1 comments:

Waqeeh Ul Hasan said...

nice one

Post a Comment