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
- 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
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
ITEM | PROPERTIES | KETERANGAN |
Form1 | Border Style | 1. Fixed Single |
Form1 | Start Up Position | 2. Center Screen |
Label1 | Caption | NUMBER 1 |
Label2 | Caption | NUMBER 2 |
Label3 | Caption | RESULT |
Text1, 2, 3 | Text | (EMPTY) |
Command1 | Caption | + |
Command2 | Cptionn | - |
Command3 | Caption | X |
Command4 | Caption | / |
Text3 | Enable | False |
Command 1,2,3 | Font Size | 18 |
- 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