Sie sind auf Seite 1von 2

HOW TO MAKE A CALCULATOR USING VB ? At first open VB and choose Standard EXE. ?

Now on the form (appeared on the screen) change the back colour to Black. ? Now
change the caption of the form to calculator. ? Now add 2 labels. change the cap
tion of the labels to scientific calculator and caption of the label 2 to Jawaha
r navodaya vidyalaya. ? Now add 2 timer control and change the interval of both
the timer to 200 & 500 respectively. figure of the VB after these process
? Now add a text box & change its back colour to yellow. ? Now add a shape in th
at form. ? Change the shape of the shape to rounded rectangle and the back style
to opaque. ? Now insert a command button and after copy and paste it 11 times.
for the first time it will ask you do you want to make a control array click on ye
s. ? Now change the caption of the 11 commands to 1,2,3,4,5,6,7,8,9, .&0. ? Now
add a frame to the form and change his back colour to light purple and border st
yle to none. fig. of the VB application after these 6 steps.
? Now insert another command button in the frame and change it s caption to +/- and
back colour to red and style to graphical. ? Now insert another command button i
n the form and change it s caption to = ? Now add another command button then copy a
nd paste it,5 times. At first it will ask you do you want to make a control array
click on yes. ? Change the caption of all the command button to +, -, /, *, % re
spectively and change the back colour of all the command button to red and chang
e the style to graphical. ? Now insert another command button and change its cap
tion to C and back colour to aqua. fig. of the VB application after these 5 step
s.
? Now add another command button and change its caption to OFF and back colour t
o aqua. ? Now add another command button and change its caption to ON and back c
olour to aqua. ? Now add another command button then copy and paste it,9 times.
Now change its caption to sin,cos,tan,sqrt, abs, md, log and atn. ? Now add anot
her command button and change its caption to MEMR. ? Now add another command but
ton and change its caption to MEMW. fig. of the VB application after these 5 ste
ps.
? Now define the variable as follow:- Dim op As String Option Explicit Dim i As
Integer Dim exp1 As Double Dim exp2 As Double Dim Result As Double Dim count1 As
Integer Dim scitype As String Private X As Double Dim mem As Variant ? Now add
the code in that application as follow:- Private Sub Command1_Click(Index As Int
eger) If count1 = 0 Then Text1.Text = " " MsgBox ("Calculator is not on") End If
If count1 = 1 Then Text1.Text = " " count1 = count1 + 1 End If If count1 > 1 The
n Text1.Text = Text1.Text & Command1(Index).Caption End If End Sub ------------------------------------------------------------------------------------------------------- Private Sub Command10_Click() Text1.Text = mem End Sub ------------------------------------------------------------------------------------------------------- Private Sub Command2_Click() Text1.Text = -Val(Text1.Text) End Sub
-------------------------------------------------------------------------------------------------------Private Sub Command3_Click() If count1 > 0 Then exp2 = Val(Text1.Text) Select Ca
se (op) Case "+" Result = exp1 + exp2 Text1.Text = Result count1 = 0 Case "-" Re
sult = exp1 - exp2 Text1.Text = Result count1 = 0 Case *" Result = exp1 * exp2 Te
xt1.Text = Result count1 = 0
Case " /" Result = exp1 / exp2 Text1.Text = Result count1 = 0 Case "%" Result =
(exp1 / 100) * exp2 Text1.Text = Result count1 = 0 End Select End If End Sub ------------------------------------------------------------------------------------------------------------- Private Sub Command4_Click(Index As Integer) Result
= exp1 exp1 = Result + Val(Text1.Text) Text1.Text = " " op = Command4(Index).Ca
ption End Sub --------------------------------------------------------------------------------------------------------------Private Sub Command5_Click() Result = 0 exp1 = 0 exp2 = 0 Text1.Text = " " count
1 = 1 End Sub -------------------------------------------------------------------------------------------------------- Private Sub Command6_Click() count1 = 0
Text1.Text = "" End Sub -------------------------------------------------------------------------------------------------------- Private Sub Command7_Click() R
esult = 0 exp1 = 0 exp2 = 0 count1 = 1 Text1.Text = "0" End Sub -----------------------------------------------------------------------------------------------

---------------Private Sub UpdateLog() Trim (Form1.Text1.Text) End Sub ------------------------------------------------------------------------------------------------------- Private Sub Command8_Click(Index As Integer) scitype = Command8(Index).Caption
Select Case (scitype) Case "sin" Text1.Text = (Text1.Text * 3.14) / 180 Text1.T
ext = Math.Sin(Val(Text1.Text)) count1 = 0 Case "cos" Text1.Text = (Text1.Text *
3.14) / 180 Text1.Text = Math.Cos(Val(Text1.Text)) count1 = 0 Case "tan" Text1.
Text = (Text1.Text * 3.14) / 180 Text1.Text = Math.Tan(Val(Text1.Text)) count1 =
0 --------------------------------------------------------------------------------------------------------------Case "sqrt" Text1.Text = Math.Sqr(Val(Text1.Text)) count1 = 0 Case "abs" Text1.T
ext = Math.Abs(Val(Text1.Text)) count1 = 0 Case "rnd" Text1.Text = Math.Rnd(Val(
Text1.Text)) count1 = 0 Case "log" Text1.Text = Math.Log(Val(Text1.Text)) count1
= 0 Case "Atn" Text1.Text = Math.Log(Val(Text1.Text)) count1 = 0 End Select End
Sub --------------------------------------------------------------------------------------------------------------- Private Sub Command9_Click() mem = Text1.T
ext End Sub --------------------------------------------------------------------------------------------------------------Private Sub Form_Load() End Sub --------------------------------------------------------------------------------------------------------- Private Sub Timer1_Ti
mer() Label1.BackColor = RGB(256 * Rnd, 256 * Rnd, 256 * Rnd) End Sub -------------------------------------------------------------------------------------------------------- Private Sub Timer2_Timer() Label2.BackColor = RGB(256 * Rnd, 25
6 * Rnd, 256 * Rnd) End Sub ---------------------------------------------------------------------------------------------------------

Das könnte Ihnen auch gefallen