VB.
NET:VARIABLES
INSTRUCTOR: GERALD EMERSON S. CORPIN
LET’S DO THIS!
VARIABLE INITIALIZATION
Initialized (assigned a value) with an equal “=“ sign followed by a constant
expression
Syntax:
variable_name = value
Example:
Dim StudentID as String
StudentID = “10-1-00001”
OR
Dim StudentID as String = “10-1-00001”
ACCEPTING VALUES FROM USER
ReadLine() / Console.ReadLine is used for accepting input from the user in a
Console class and store it into a variable
VB.NET:
OPERATORS
INSTRUCTOR: GERALD EMERSON S. CORPIN
OPERATORS
Symbols that tells the compiler to perform specific mathematical or logical
manipulations
Arithmetic Operators
Comparison Operators
Logical Operators
Assignment Operators
ARITHMETIC OPERATORS
a = 2, b = 6
Operator Description Example
^ Raises one operand to the power of another 64 = a ^ b
+ Addition 8=a+b
- Subtraction -4 = a – b
* Multiplication 12 = a * b
/ Floating Division (data type: Single, Double) 3=b/a
\ Integer Division 3=b/a
MOD Modulus Operator and remainder of after an 0 = b MOD a
integer division
COMPARISON OPERATORS
a = 2, b = 6
Operator Description Example
= Condition = true if two values are equal False
<> Condition = true if two values are NOT equal True
> Condition = true if value of left operand is greater than the right False
operand
< Condition = true if value of left operand is less than the right True
operand
>= Condition = true if value of left operand is greater than or equal False
to the right operand
<= Condition = true if value of left operand is less than or equal to True
the right operand
LOGICAL OPERATORS
Operator Description
And Result is TRUE if ALL comparison operators are TRUE
Or Result is TRUE if EITHER comparison operators are TRUE
Not Result is TRUE if ALL comparison operators are FALSE
Xor Result is TRUE if both expressions are TRUE or both expressions are FALSE
ASSIGNMENT OPERATORS
Operator Description Example
= Simple assignment operator, Assigns values from right side operands to left side operand C = A + B will assign
value of A + B into C
+= Add AND assignment operator, It adds right operand to the left operand and assigns the C += A is equivalent
result to left operand to C = C + A
-= Subtract AND assignment operator, It subtracts right operand from the left operand and C -= A is equivalent
assigns the result to left operand to C = C - A
*= Multiply AND assignment operator, It multiplies right operand with the left operand and C *= A is equivalent
assigns the result to left operand to C = C * A
/= Divide AND assignment operator, It divides left operand with the right operand and C /= A is equivalent
assigns the result to left operand (floating point division) to C = C / A
ASSIGNMENT OPERATORS (CONT.)
Operator Description Example
\= Divide AND assignment operator, It divides left operand with the right operand and C \= A is equivalent
assigns the result to left operand (Integer division) to C = C \A
^= Exponentiation and assignment operator. It raises the left operand to the power of the C^=A is equivalent
right operand and assigns the result to left operand to C = C ^ A
&= Concatenates a String expression to a String variable or property and assigns the result to Str1 &= Str2 is same
the variable or property. as
Str1 = Str1 & Str2
ORDER PRECEDENCE
Determines the grouping of terms in an expression
Certain mathematical operators have higher precedence than others
For example, x = 7 ^ 2 + 3 * 2 /1 -5;
here, x is assigned 50, not 90 because the order of precedence is: ^, *, /, +, -
Operator Symbol
() Parenthesis
^ Exponentiation
* Multiplication
/ Floating Division (Division)
+ Addition
- Subtraction