Let us create a program enhancing the result from Sample Program #1. Aside of stating only the sum, combine the statement "The sum is" to make a human like calculator.
'LONG METHOD STYLE CODE
Private Sub cmdcal_Click()
Dim a, b, c As Integer
a = Val(txtn1.Text)
b = Val(txtn2.Text)
c = a + b
txtsum.Text = "The sum is " + Trim(Str(c))
End Sub
'SHORT METHOD STYLE CODE
Private Sub cmdcal_Click()
txtsum.Text = "The sum is " + Trim(Str(Val(txtn1.Text) + Val(txtn2.Text)))
End Sub
Discussion:
Basing on the previous example, we simply add the statement (THE SUM IS) which is inside a double quotation mark. The double quotation mark will tell the compiler that this statement does not contain any variable. To fuse it with a variable, just add a plus sign in between.