How To Create A Simple Calculator in Visual Basic 6.0: $0.01 Web Hosting
How To Create A Simple Calculator in Visual Basic 6.0: $0.01 Web Hosting
How To Create A Simple Calculator in Visual Basic 6.0: $0.01 Web Hosting
0: 15 Steps
1 of 4
http://www.wikihow.com/Create-a-Simple-Calculator-in-Visual-Basic-6.0
Steps
Open Visual Basic 6.0 and create a new Standard EXE Project. Standard
EXE projects give you a handful of commands and tools, useful to develop simple
Understand the project screen. In the center of the screen will be a box with a lot
of dots. This is your form. A form is the place where you will add the various
Drag a label onto the form, and change the caption of the label to "Enter first
number".
02-Dec-14 22:55
2 of 4
http://www.wikihow.com/Create-a-Simple-Calculator-in-Visual-Basic-6.0
Create a textbox to the right of the first label. Remove any text that appears
Create another label and change the caption to "Enter second number" and
Drag and create four command buttons below these two labels. Change the
inside the textbox by changing blanking the "Text" field in properties box.
respectively.
Create another label with a caption "Result" and a textbox to the right of it
below the four command buttons. This textbox will be used to display the result.
To start coding, in the project explorer, click on the form and then select the
left-most button. It will take you to the coding screen.
Click on the list box in the top-left of the coding screen. One by one, click on all
the commands (Command1, Command2, etc) so that the outline coding of them
will be visible to you on your coding screen.
10
Start the coding for the add command (Command1). The code will be as
follows:
Private Sub Command1_Click()
a = Val(Text1.Text)
b = Val(Text2.Text)
r=a+b
Text3.Text = r
End Sub
11
Code for the subtract command (Command2). The code will be as follows:
Private Sub Command2_Click()
a = Val(Text1.Text)
b = Val(Text2.Text)
r=a-b
Text3.Text = r
End Sub
02-Dec-14 22:55
3 of 4
12
http://www.wikihow.com/Create-a-Simple-Calculator-in-Visual-Basic-6.0
Code for the multiply command (Command3). The code will be as follows:
Private Sub Command3_Click()
a = Val(Text1.Text)
b = Val(Text2.Text)
r=a*b
Text3.Text = r
End Sub
13
Code for the divide command (Command4). The coding will be as follows:
Private Sub Command4_Click()
a = Val(Text1.Text)
b = Val(Text2.Text)
r=a/b
Text3.Text = r
End Sub
14
15
Ad
Save your project and your form. Make your project and save it as a .exe file
on your computer; run it whenever you want!
Training Materials
Customizable training materials to teach soft skills workshops.
natural weight
gain?
skiing?
Fitbit?
Yes I can
Yes I can
Yes I can
Yes I can
Tips
Add colours to the form and the text boxes, using the properties box to
make it appear colourful!
You can create different variations of a simple calculator. Try using
option box instead of command buttons.
02-Dec-14 22:55
4 of 4
http://www.wikihow.com/Create-a-Simple-Calculator-in-Visual-Basic-6.0
Article Info
Thanks to all authors for creating a page that has been read 293,855 times.
02-Dec-14 22:55