Professional Documents
Culture Documents
...
2
: (:
3
2 ....................................................................................................
7 ............................................................................ :
7 .......................................................................... :
8 .............................................................................................
10 ....................................................................................... :
11 ............................................................... :variables
12 .............................................................. :Constants
12 .......................................................................... :Comments
14 ............................................................................. :operators
16 ..................................................................................... if...else
17 ............................................................................... :
18 ............................................................................. :
18 ......................................................................... :Loops
4
18 ........................................................................................ : for
19 ......................................................................................... : do
20 ...................................................................................... : while
20 .................................................................................. : for each
21 ....................................................................................... :goto
22 .............................................................................. :Methods
22 ........................................................................................ :
23 ..................................................................................... :
23 ........................................................................................ :
25 ................................................................................ :arrays
25 ........................................................................... :structures
27 ...................................................................... :Enumerations
Me 31 .......................................................................................... :this
32 ........................................................................... :Inheritance
34 ........................................................................... :Interfaces
5
36 ....................................................................... :Constructors
37 ......................................................................... :Properties
39 ....................................................................................... :
39 .............................................................. :namespaces
40 ................................................................................ :
43 ................................................................................................. :
6
:
:
.
:
Basic
Beginners All-purpose Symbolic Code
.1963
7
1990 Visual Basic 1.0
6
.
console
.asp.net
(:
}{
:
(:
8
6
VBA
.
Operator Overloading
Input Box
.
:
.
9
:
.
;int number
)int Number; //No problem :
.
10
:variables
Runtime
Data Type
.
;int number
;int number2 = 15
;string name
;"string name2 = "Ahmed
11
:Constants
.
:Comments
Compiler
.
'This is
'a multi - line
'Comment
12
//This is a single - line comment
/*This is
a multi - line
Comment*/
:Data type
. boolean integer string
#
int Integer
long Long
short Short
byte Byte
float Single
double Double
decimal Decimal
DateTime Date
string String
char Char
bool Boolean
object Object
13
:operators
.
#
+ +
- -
* *
/ /
/ \
% Mod
^
;int number Dim number As Integer
;number = 10 number = 10
;number += 10 number += 10
;number -= 10 number -= 10
;number *= 10 number *= 10
14
;int number Dim number As Integer
;number /= 10 number /= 10
;number /= 10 number \= 10
> >
=> =>
< <
=< =<
== =
=! ><
&& and )(
|| Or )(
Number++
Number--
15
:Flow control
.
if...else
if (job == "Doctor")
{
state = true;
}
else if (job == "Nurse")
{
state = true;
}
else
{
state = false;
}
}
16
:
Select Case op
Case "+"
result = 5 + 5
Case "-"
result = 5 - 5
Case "*"
result = 5 * 5
Case "/"
result = 5 / 5
Case Else
result = 0
End Select
switch (op)
{
case '+':
'+'
result = 5 + 5;
break
break;
case '-':
'
result = 5 - 5;
break
break;
case '*':
'*'
result = 5 * 5;
break
break;
case '/':
'/'
result = 5 / 5;
break
break;
default
default:
result = 0;
break
break;
}
17
:
string access_state=password==
=password=="pass123" ? " correct": "incorrect";
"incorrect
:Loops
.
: for
18
for (int number = 0; number < 10; number++)
{
Console.WriteLine(
.WriteLine("Number : "+ number);
}
: do
int number = 0;
do
{
Console
Console.WriteLine("Line:{0}", number);
number++;
}
while (number <= 5);
19
: while
int number = 0;
while (number < 9)
{
Console
Console.WriteLine("Line :{0}",
, number);
number++;
}
: for each
20
string name = "Ahmed";
foreach (char
char letter in name)
{
Console
Console.WriteLine(letter);
}
:goto
string founder;
ask: Console.Write(
.Write("who
"who is the founder of microsoft?");
microsoft?"
founder = Console.ReadLine();
if (founder == "bill gates")
{
Console
Console.Write("You're right");
}
else
{
Console
Console.WriteLine("False !!");
goto ask;
}
21
:Methods
.
'Create Procedure
Public Sub myProc()
'Do Something
End Sub
'Create Function
Public Function myFunction() As String
Return "Something"
End Function
//Create Procedure
public void myProc()
{
//Do Something
}
//Create Function
public string myFunction()
{
return "Something";
"Something"
}
22
:
myProc()
myProc();
Return a + b
End Function
23
}
Return a + b
End Function
//Passing by reference
public static int myFunction(ref int a, ref int b)
{
return a+b;
}
24
:arrays
.
:structures
) (...
.
25
'Creating the structure
Structure student
Public name As String
Public age As Integer
Public address As String
//Methods
26
public string ShowStudent()
{
return "Student name: " + name
+ " Student age: " + age
+ " Student address: " + address;
}
}
:Enumerations
.
27
Friday
Saturday
Sunday
End Enum
:Handling Exceptions
Runtime
...
.try...catch
28
Console.WriteLine(
.WriteLine("Enter your age:")
Try
age = Console.ReadLine
Console
Catch ex As Exception
Console.WriteLine(Err.Description)
.WriteLine(Err.Description)
Finally
Console.WriteLine(
.WriteLine("press
"press any key to leave...")
leave..."
End Try
Console.ReadKey()
.ReadKey()
int age;
Console.Write(
.Write("Enter your age:");
try
{
age = int.Parse(Console.ReadLine());
}
catch (Exception
Exception Err)
{
Console
Console.WriteLine(Err.Message);
}
finally
{
Console
Console.WriteLine("press
"press any key to leave...");
leave..."
}
29
:Classes and Objects
structure
.class
'Creating a class
Public Class Car
'Class members
End Class
//Creating a class
public class Car
{
//Class members
}
30
:this Me
Me
) this
.
End Class
:Inheritance
Main class
.Derived class
(... )Animal
.( Animal )
'Main class
Public Class Animal
Private name As String
'Derived Classes
Public Class Lion
Inherits Animal
End Class
32
Public Class Tiger
Inherits Animal
End Class
//Main class
public class Animal
{
private string name;
//Derived Classes
public class Lion:Animal
Animal
{
}
33
:Interfaces
interfaces
.
.implementation
:interface
Sub setLocation(ByVal
ByVal X As Integer, ByVal Y As Integer)
Integer
Implements ILocation.setLocation
.setLocation
Me.x = X
Me.y = Y
34
End Sub
int ILocation.GetLocation_X()
.GetLocation_X()
{
return x;
}
35
int ILocation.GetLocation_Y()
.GetLocation_Y()
{
return y;
}
}
:Constructors
.
End Class
36
public class Employee
{
private string name;
private int age;
:Properties
.public
Getter
.Setter
37
Public Class Employee
Private name As String
Private age As Integer
End Class
38
public int age_property
{
get { return age; }
set { age = value;
value }
}
}
:
. " "
Employee emp=new
new Employee();
emp=null;
:namespaces
Imports
. using
Imports System
Imports System.Collections.Generic
Imports System.Linq
39
Imports System.Text
Imports System.Threading.Tasks
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
:
:
MsgBox("" , MsgBoxStyle.Information,
MsgBoxStyle ")"
MessageBox.Show("" ,
"", MessageBoxButtons.OK,
.OK,
MessageBoxIcon.Information);
.Information);
40
: static members
.
'static method
Public Shared Function getName()
Return name
End Function
End Class
Sub Main()
'use static members
Employee.name
.name = "Khalid"
Dim myName As String = Employee.getName
End Sub
41
//static method
public static string getName()
{
return name;
}
42
:
.
:
http://www.mobarmijoun.com
:
Khalid_ESSAADANI@Hotmail.fr
ESSAADANIKHALID@Gmail.com
:
www.facebook.com/ESSAADANI.Khalid
www.facebook.com/Khotwa.Amam
43