Documente Academic
Documente Profesional
Documente Cultură
2
3. Choose from new project window “Standard exe” then
click open button.
3
4
Tool Box
The toolbox contains the controls
that you place on the Form window.
6
1- picture : the pic.box control is used to display images,
( and the images are set with the picture property) .
2- textbox : this control displays text that the user can edit
, (text property which can set the text on the control or read the
text that the user enter) .
3- label : this control displays text on the form that
user can’t edit ( set the label’s text with the caption property).
7
6- Option Button: its appear in groups and the
user can chose only one of them , its property is
checked true ( if checked ) false otherwise .
8
Toolbar
9
Properties box
Properties are detailed descriptive information about
a control. )
Name
Alignment
BackColor
Caption
ControlBox
Enabeld
Font
FontColor
Visible
Width
10
Project Explorer
11
?Where you are write code
1
2
3
1- Private Sub
2- code (actions…)
3- End Sub
Note : you can write comments to refer to:
--- purpose of program or any part of code
so write as:
comment is written in green
13
How you are write code?
The syntax to set the property of an object or to pass
certain value to it is :
Object.Property =value
Examples:-
Private Sub Command1_click
Label1.Visible=false
Label2.caption=“MTI”
End sub
Text1.Text=”You are correct!”
14
First program
15
The program steps
Start Microsoft visual basic 6.0 .
Choose from new project window “Standard
exe” then click open button.
You have to select one text and 4 buttons.
Then you go to every tool and change it’s
property
1- Text text: no fill
2- Command1 caption: Name
3- Command2 caption: Tele.No
4- Command3 caption: Age
5- Command4 caption: Exit 16
How to write code ?
1- Command button1:”Name”
The output :
18
In the code window we can see:
Object window:
Where it shown all
objects using it.
Procedure window: Here is the procedures
19
You have to save your First project
20
My first small calculator program
21
:The tools of program
1. Command1 caption: ADD
2. Command2 caption: SUB
3. Command3 caption: Exit
4. label box1 caption: Number1
5. label box2 caption: Number2
6. label box3 caption: Number3
7. Textboxes text: no fill
22
:The code of program
23
•The output:
24
Operators in Visual Basic
we need to use various mathematical operators (except add + , sub - )
Arithmetic Operators :
12=3*4 Multiplication *
3=12/4 Division /
26
Variables
27
:Declaring Variables
Dim Name As Type
'dimming'
Reserve space to var. var.name being type of var.
rasha= “Hessian”
28
Types of Variables
Numeric
String
Boolean
Variant
Data
Object
29
Data Type Definition Characters
String “Hello”
Integer 5
Long 92883
Single 39.2932
Double 983288.18
30
What is type of declaration and scope of
Variables?
General declaration
Form level
Button level
31
Example
Do the previous calculator program using variable
Command1
Dim x as double
Dim y as double
X=val(text1.text)
Y=val(text2.text)
Text3.text=x+y
Command2
Text3.text=x-y
Arrays
An array is a group of variables that all have the
same name but which are each uniquely
identified by an index number. ( i , j )
E.g. if we want to declare an matrix of one
Example:
Const Mynumber As Integer = 64
Then assign it to text:
Text1.Text = Mynumber
34
Conditional Statements
35
Conditional Statements
If Statement
[ The If...Then…Else statement examines the truthfulness
of an expression] .
Select Case
[Visual Basic offers the alternative of jumping to the
statement that applies to the state of the condition ].
36
If Statement
If condition ( expression= value) Then
Statement block
End If
If ( ) ا??لشرط ي??كتبهناThen ( ()ا??لكود ا??لذيس??يعملإذا ت???حققا??لشرط
If-else Statement
If condition ( expression= value) Then
statementblock-1 (action if true )
Else
statementblock-2 (action if false )
End If
If ( ) ا??لشرط ي??كتبهناThen ( ) ا??لكود ا??لذيس??يعملإذا ت???حققا??لشرطElse ( ()ا??لكود إذا ل??م? ي??تحقق
37
Example
Take a grade from a student then
give him his score
<50 Fail
>50 Pass
If –Elseif Statement
If condition1 ( expression= value) Then
statementblock-1 (action if true )
Elseif condition2 ( expression= value) Then
statementblock-2(action if true )
Else
statementblock-4(action if false )
End If
39
:The comparison operators
40
The Logical operators:
A logical operation is one that is performed on one or
two expressions to check the truthfulness or falsity.
41
:Working examples
Logical operators are performed only on
conditional statements.
Only we will use in our work (AND, OR).
Meaning Logical Factor
42
:And logical operator
i.e. Condition1 AND Condition2=??!!
where Condition1, Condition2 variables.
Condition1 AND Condition2 Condition1
Condition2
FALSE FALSE FALSE
46
Code:
Private Sub Command1_Click()
End Sub
47
Timer Example
Write a program that make the font size of an
sentence to change every1s then out msg box
inform you the font size when it reach to 20
Loop Statement
49
Loop Statement
Do…Loop
For…Next
While…Wend
50
For…Next
For counter = start To end [step increment]
statements
Next counter
Variable name
Ex:
Dim a As Integer
For a = 1 To 10
Beep()
Next a
51
Example
Calculate the sum numbers from 1 to 10
Parallel port
888 IN/OUT
889 IN
890 OUT