Example of VB Expression Program - Create a Simple Calculator V1

Example of VB Expression Program - Create a Simple Calculator Previously we have learned about the expression in Visual Basic, this time we will apply what we have learned previously to VB program, this time we will make a simple calculation program or a calculator, well let the following tutorial:

1. First, as usual, open and run Visual Basic, and create a new Standard EXE program
2. Second, add three labels, three text boxes, and four command buttons, set extent,
3. Third, change the properties
ITEMPROPERTIESKETERANGAN
Form1Border Style1. Fixed Single
Form1Start Up Position2. Center Screen
Label1CaptionNUMBER 1
Label2CaptionNUMBER 2
Label3CaptionRESULT
Text1, 2, 3Text(EMPTY)
Command1Caption+
Command2Cptionn-
Command3CaptionX
Command4Caption/
Text3EnableFalse
Command 1,2,3Font Size18


- Border Style Fixed Single In Form function so extensive form can’t be changed when run
- Start Up Position "Center Screen", so Form position when run in the middle of the screen
- Enable "False" In Label3 meant that text3 can’t use.

So like this:
4. If its already, please write the following script:

Private Sub Command1_Click()
a = Val(Text1) 'The value of b according to what was written in text1
b = Val(Text2) 'The value of b according to what was written in text2
c = a + b 'The value of c is a + b, If a = 1 and b = 2, then the value of c = 3
Text3 = c 'Text 3 = The value of the variable c
End Sub

Private Sub Command2_Click()
a = Val(Text1)
b = Val(Text2)
c = a – b
Text3 = c
End Sub

Private Sub Command3_Click()
a = Val(Text1)
b = Val(Text2)
c = a * b
Text3 = c
End Sub

Private Sub Command4_Click()
a = Val(Text1)
b = Val(Text2)
c = a / b
Text3 = c
 End Sub

5. The last step, try to run the program and you will find:

The program automatically, appear / start from the middle (Center Screen)
We will not be able to widen the form extensive, when the program runs (Fixed Single) Text3 can’t be clicked like text1 and 2 (Enabled = false)
That is the tutorial about how to make a simple calculator
So this is enough for tutorial this time, Good luck

Popular Posts