VB6 Tutorial 08: Operators & Expressions

Posted On 2018-03-23 by VB6Boy
Keywords: visual,basic,vb6,visualbasic,tutorial,basic,beginner,Operators,Expressions
Tags: VB6 Tutorials Windows
Views: 61

Looking for the more of the VB6 Tutorial? Here is the tutorial index.

An operator in a programming language is a symbol that tells the compiler or interpreter to perform specific mathematical, relational or logical operation and produce final result.

+Addition>=Greater than or equal to
-Subtraction<>Not equal to
*Multiplication=equal to
/Division&String Concatenation
\Integer DivisionAndLogical And
ModModulo DivisionNotLogical Not
<Less thanOrLogical Or
>Greater thanXorLogical Xor
<=Less than or equal to^Power

Assigning values to variables : '=' operator

The Assignment operator (=) is used to assign a value or an expression to a variable. When you assign a value, its not the same as the Equal to operation, but the value is copied to a variable. Besides assigning values and expressions, you can assign a variable to a variable also.



'=' , '+' are the operators.

x,a,b are the operands and 'a+b' is an expression. x=a+b is a statement.

The following program will print 20.

Private Sub cmdDisplay_Click()
    Dim num As Integer, r As Integer, n As Integer
    n = 10
    r = n ^ 2      'n to the power 2
    num = n + r / n
    Print num
End Sub

Output : 20

The Integer Division Operator ('\')

The Integer Division operator('\') eliminates the decimal part after division.


Private Sub cmdDivision_Click()
    Dim a As Double, b As Double, c As Double
    a = 12: b = 5
    c = a \ b
    Print c
End Sub

Output : 2

The 'Mod' operator

The Mod operator is used to calculate remainder.

Example :

Private Sub cmdShow_Click()
    Dim remainder As Integer, num As Integer
    num = 21
    remainder = num Mod 10
    Print remainder
End Sub

Output : 1

Boolean Operators : And, Or, Not, Xor

To learn about Boolean operators, you first need to have the concept of If-Else condition. So Boolean operators are explained in a later lesson.

Looking for the more of the VB6 Tutorial? Here is the tutorial index.

About the Author

VB6Boy has posted a total of 71 articles.

Comments On This Post

No comments on this post yet!

Do you have a thought relating to this post? You can post your comment here. If you have an unrelated question, you can use the Q&A section to ask it.

Or you can drop a note to the administrators if you're not sure where you should post.

Your IP address is:

Before you can post, you need to prove you are human. If you log in, this test goes away.

Code Links