Visual_Basic
Visual_Basic
Letters
A…Z , a…z
Digits
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Special Symbols
?, + , - , * , / , } , { , < , > , # , @ , & , ^ , % , ( , ) , !
Numeric Constants
5 , 10.5 , 20 , -40 , -10.2 , 3.14
Character Constants
Thepreviousvalueisdestroyed
Data Types
EXAMPLE
integer 200 ,10 ,-70 , 80
long (integer) 35455 , 5678943
single 115.78 ,1.907 ,3.65
double 123.78129024, 12.876097
Boolean True or False
String “Hello ,my name is Ali”
Declaring Variables
General form:
Dim Variable1 As datatype1, variable2 As datatype2 , etc.
Dim var_name1, var_name2 , … As datatype
For example:
Dim x As long
Dim y As Double
Dim Name As String, Value As Single
Dim A ,B,C As Integer
2030
StringVariable
Declaration Dim Name As String
Multiple Declarations
Dim a, b As Double
Two other types of multiple-declaration statements are
Dim a As Double, b As Integer
Dim c As Double, d As Integer
Dim a , b , c As Single , x , y As Double, i As Integer
a, b, and c are all Single; x and y are both Double
StringVariable
You can assign the value of one string variable to another.
Dim str1 As String str1 = "Hello"
Dim str2 As String str2 = "Goodbye"
str2 = str1
Print str2
Output: Hello
AssignmentStatement
Dim num As Double
Dim num2 As Double
Num =5 Num2 =4
num = 3 * num2
Print num
Output: 12
Example
Dim Name As String
Dim Num1 As Integer
Dim Today As Date
Name = " Ahmad "
Num1 = 12
Today = "12/02/2012 "
Dim x as date
x = #20/03/2012#
Print x ➔ 20/03/2012
Dim x As Date x =#12:30:44 AM#
Print x ➔ 12:30:44 AM
Example
Dim Number As Integer Number = 31
' This is ok
Number = “I didn't”
' Error: type mismatch (Number is an integer
while “I didn't” is a string)
DefaultValues for Data Types
Data type Default (Initial) value
All numeric types Zero (0)
( Integer , Long, single ,Double )
Boolean False
Char Binary 0
Arithmetic Expression
Integer division
Uses the backslash, \
7 \ 4 evaluates to 1
Floating-point division
Uses the forward slash, /
7 / 4 evaluates to 1.75
Modulus operator, Mod
Yields the remainder after Integer division
7 Mod 4 yields 3
4 mod 7 yields 4
7 mod 7 yields 0
7 mod 1 yields 0
Precedence of arithmetic and relational operators
Order of Operations
Order of precedence in arithmetic expressions from highest to lowest
1. Any operation inside parentheses ()
2. Exponentiation ^
3. Multiplication and division * /
4. Integer division \
5. Modulus mod
6. Addition and subtraction + -
Arithmetic
Arithmetic
Ex: 5 – 3 + 6 + 2*2 ➔ Result = 12
Ex: 3 + 5*(10 – 6) ➔ Result = 23
How to represent the following example in vb6
Ex: 2 – 5(6 – 9)3
➔➔Print 2 - 5 * (6 - 9) ^ 3 ➔ Result = 137
Ex: 7 + 2 * (9 / 3) – 1
Expression in parentheses 7 + 2 * (9 / 3) – 1
1. Multiplication 7 + 2 * 3 – 1 2.
2. Addition and subtraction from left to right 7 + 6 - 1 = 12
Print 7 + 2 * (9 / 3) – 1 12
How to represent the following example in V.B 6.0
F= aX2+bX+C ➔F =a*X^2+b*X+C
F= 2((X-Y)+3XY)+Z ➔ F=2*((X-Y)+3*X*Y)+Z
F= X2+Y2+Z3 ➔ F= X^2+Y^2+Z^3
F= 20X2+3X+3 ➔ F= 20*X^2+3*X+3
F=(X2+Y3)2X ➔ F=(X^2+Y^3)*2*X
Declare variables
Dim First as Integer, Second as
Integer
Dim Sum as Integer
Assign values to variables
First = val (text1.Text)
Second = val (text2.Text)
Sum= First+ Second
Print Sum
End Sub