Sunteți pe pagina 1din 53

1

? How to open VB6 from WinXP

1. Start All programs.


2. Microsoft visual studio 6.0 .

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).

4- command : this control where it used where when the


user click on it make an order .

5- frame: this control is used to draw boxes on the form


and to group other elements.

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 .

7- Check Box: lets the user to select or unselect an


option. When the Check Box is checked, its value is set
to 1 and when it is unchecked, the value is set to 0.
 You can include the statements Check1.Value=1 to
mark the Check Box and Check1.Value=0 unmark the
Check Box

8- List Box: is to present a list of items where the


user can click and select the items from the list. In
order to add items to the list, we can use the AddItem
method.

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

 The Project Explorer window, gives you a tree-


structured view of all the files in the application.

11
?Where you are write code

 First double click on tool chosen


 Then :

So Write Code In-between.


12
What is written in the code’s window?!!

 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

We have to make a program that will show


“name”, “telephone number”, “age”, “Exit”.??!

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”

Then double click on next tool


2- Command button2:”Tele.no.”
Private Sub Command2_Click()
text2.Text = "028254335"
End Sub
3- Command button3:”Age”
Private Sub Command2_Click()
text2.Text = “32"
End Sub 17
4- Command button4:”Exit”
Private Sub Command2_Click()
End
End Sub
Then you can Start the program by click on then you
can Stop it by click on

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

which have to be run.

19
 You have to save your First project

File “Save Form as “


Then “Save Project as”
then “Make Project
.exe.”

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 :

Example Mathematical function Operator


16=4^2 Exponential ^

12=3*4 Multiplication *

3=12/4 Division /

Mod 4=3 15 Modulus (return the Mod


remainder from an integer
division)
4=4\19 Integer Division (discards the \
decimal places)
Visual"&"Basic" String concatenation + or &
="
25
"Visual Basic"
You have to save your second project

“ File “Save Form as “ then


“Save Project as” then
”. “Make Project .exe

26
Variables

27
:Declaring Variables
 Dim Name As Type

'dimming'
Reserve space to var. var.name being type of var.

Ex: Dim rasha As String

 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?

Module level/general declaration

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

dimension of 25 var. to write a student names of


a section.
So: Dim StuName(25) As String
Ex: StuName( 20 ) = “ ali “
( here : VB. Reserve a place for 25 var. and there types are string )
( Note: its important to know that index numbers for arrays start from StuName(0) var. to
StuName(24) var. ).
33
:Constant declaration
 Const name [As type] = value

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 )

Elseif condition3 ( expression= value) Then


statementblock-3(action if true )

Else
statementblock-4(action if false )

End If

39
:The comparison operators

Meaning Comparison Factor


equals =
Not equals <>
Greater Than >
Less Than <
Greater Than OR equals =>
Less Than OR equals =<

40
The Logical operators:
 A logical operation is one that is performed on one or
two expressions to check the truthfulness or falsity.

Meaning Logical Factor


Logical Factor" And” AND
”Logical Factor" OR OR
” Logical Factor" Vice NOT
One of the conditions True XOR
then Result True

41
:Working examples
 Logical operators are performed only on
conditional statements.
 Only we will use in our work (AND, OR).
Meaning Logical Factor

Logical Factor" AND


And”
Logical Factor" OR
”OR

42
:And logical operator
i.e. Condition1 AND Condition2=??!!
where Condition1, Condition2 variables.
Condition1 AND Condition2 Condition1
Condition2
FALSE FALSE FALSE

FALSE FALSE TRUE

FALSE TRUR FALSE

TRUE TRUE TRUE


43
:OR logical operator
i.e. Condition1 OR Condition2=??!!
where Condition1, Condition2 variables.
Condition1 OR Condition2 Condition2 Condition1
FALSE FALSE FALSE

TRUE FALSE TRUE

TRUE TRUR FALSE

TRUE TRUE TRUE


44
Example
Take a grade from a student then
give him his score
<50 Fail
>50 & <65 Pass
>=65 &<75 good
>=75 &<85 V.good
>=85 Excellent
:MsgBox, InputBox
 A message box is a dialog box you display to give the
user information. (subtype from form).
i.e.

46
 Code:
Private Sub Command1_Click()

MsgBox ("Welcome To Our


Course")

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

S-ar putea să vă placă și