You are on page 1of 54

University of Sulaimany

College of Engineering
Building Construction Department







Computer Programming
Visual Basic








Name of Teacher: Aree Anwer Najib

Name of Student: Hawraz Muhammed Abdurrahman

Second Stage

Group B









2010-2011



Visual Basic
Introduction

Visual Basic was developed by Microsoft to extend the capabilities of BASIC by adding objects
and event-driven programming: buttons, menus, and other elements of graphical user interfaces
(GUIs). Visual Basic can also be used within other Microsoft software to program small routines.
(From Britannica Encyclopedia)

Opening the program (Visual Basic)

There are two ways for opening the program which are illustrated below.







Click on start then a small window will be opened to you as shown in the next page.



Then click on All Programs another small window will appear


A list will appear which includes all the programs installed on your computer, search for the
program named (Microsoft Visual Studio 6.0) click on it you will be shown the short cut of the
program, by clicking on it the program opens)



Or you can open the program directly from the desktop (in this case a short cut of the program
must have been placed on the desktop)
Only by (Double clicking on the short cut of the program the program opens)


((Verily Allah does not look to your bodies nor to your possessions
but He looks to your hearts and your actions))



The fist time you open the program a window as shown below will appear on the screen



And we must select (Standard EXE) as shown above and then click on (Open) then the actual
face of the program appears as shown.


Now, lets describe the most important parts of the program



Tool box: which is located on the left part of the screen and contains many
important function which are fundamentals for making any program (simple or
complex)
If the tool box is not shown on the face of the program we can bring it back by
clicking on view (from the menu bar) and then selecting tool box as illustrated
below.

The picture shown above shows the menu bar of Visual Basic
















Another window located on the right side of the program which
as called as Project window shows the number of forms that you
have in your project.
The picture shown aside is the Property window; this is one of
the most important windows this gives the properties of any
object that is brought from the tool box, Property of the
form..etc.
We will give more information on this window in later
examples...

Introducing parts of toolbox

1. Label : used to define (a project, text or give extra information on certain object)
Actually label is created to provide more information on other objects.
When talking about Label we have to mention one of its most important property which is
called as Caption
Caption: Returns/sets the text displayed in an objects title bar or below an objects icon.
Example: Draw a label and change its caption property to University of Sulaimany

You must draw a Label then you must go to the property window and select caption and change
it to university of Sulaimany.



Before change


After changing the Caption property










There is another way which is used to change the Caption property of a Label
Caption Property of a Label can be changed also by coding the form of the project.
After double clicking on the form window, another window opens which is shown below


Starting by Private Sub Form_Load() and ends with End Sub

You must write what ever you want to be shown on the label in the space provided between
Form_Load and End Sub as shown below.



If you want to change the Caption property of a Label you must write the cods in the form load in
this way
Label1.caption= University of Sulaimany

Command: its one of the most important functions in Visual Basic through which operations are
taken.
Command is used to perform required operation.






When we draw a command
on the form, we see it
appears as (Command1,
Command2,
Command3.etc)
Commands have Caption
property just like Labels,
and the caption property is
changed just like changing
Caption property of a
Label.

Example: Draw two commands and change their Caption properties to English and Kurdish.
Solution:
1. We can change the caption property of a command from the property window of the
command.
2. we can change the caption property of a command by coding the form load in this way

*Double click on the form load and write { command1.caption = Kurdish} press enter and
write {command2.caption = English}


**Coding commands

We can write codes for a command by double clicking on the command.
A window will appear starting with Private Sub Command2_Click() and ends with End Sub
And you must write your codes in between them.

Example:
Draw a Label and two Commands
Write the codes in the first command so that when you click on it the label will show
(Kurdistan)
And when you click on the second command the label will show (Turkey)
Change their Caption property to Kurdish and Turkish

Solution


Draw two commands and a Label
Double click on the first command and write.

Private Sub Command1_Click()
Label1.Caption = "Kurdistan"
End Sub

Double click on the second command and write.
Private Sub Command2_Click()
Label1.Caption = "Turkey"
End Sub











Finding Area

In this lecture we are going to use what we have learned before for finding area of regular
shapes.



By using Commands, Labels and lines draw the shape of a triangle and a trapezoid with all the
given information and then write codes in the command named (Calculate) for finding the
summation of the areas.



For the Triangle we have four Labels.
The Caption property of the first Label1 is
changed to Height
The Caption property of the second Label1
is changed to 2
The Caption property of the third Label1 is
changed to Base
The Caption property of the fourth Label1 is
changed to 2




















Based on the fact mentioned above, we have better to change the name of the labels in our
programs to names that will suit their function in the program, this will be very useful and will
reduce errors.
Unless working with the codes will be difficult.

Changing names of certain objects is quiet easy.
Go to the property of the object (Command, Label,etc) and then change its name to the desired
name.
















For the Trapezoid we have six Labels.
The Caption property of the first Label1 is
changed to Length of first side
The Caption property of the second Label1
is changed to 2
The Caption property of the third Label1 is
changed to Height of the trapezoid
The Caption property of the fourth Label1
is changed to 1.5
The Caption property of the fifth Label1 is
changed to Height of the Length of second
side
The Caption property of the sixth Label1 is
changed to 3
What is the difference between Caption and Name of a Label?
Name: This property is used to identify an object in code
Caption: This property is used as a text displaced in an objects title bar or below an objects
icon.
H2
B2
H2 and B2 are the new names for the second
and the fourth caption of theTriangle.





Finally the code which must be written in the Calculation command must be as follow
Private Sub Command1_Click()
A = 0.5 * B2 * H2 + (((L1 * 1 + L2) / 2) * H1)
End Sub



Text Box
We use text boxes to allow us make changes in the program while we are in run
mode.


























We have 5 text boxes and 6 labels and one command,
L1,L2 and H1 are the new names for the
first, second and the third caption of the
Trapezoid.
L1
H1
L2
You should draw interface like the one shown below

We write the codes in the command.
We change the name of the text boxes to namees which will suit the logic of the program,
Changing names of the texts are necessary and is quiet easy as it can be done in the property
window appearing in the left part of the screen.














































Private Sub Command1_Click()
On Error Resume Next

A = 0.5 * B2 * H2 + (((L1 * 1 + L2) / 2) * H1)


End Sub


((There can be no better present given to children by any father than a
good education))




tj: aj. t ,, ;tt, ,.,, r .j,, .j _. .,.i: r _t j
.:,jt, _tj,t., , .,,..t,, _,: tt:,t t .,,.i .,:: it aj,
:.,,..t,, j _.i _t j _. _i,: , ..i _tjt ;tt,


Note Pad

In this lecture we are going to make an application, just like those used allover the world, but the
one we make will be simpler, but some how will be an amazing program.
Finally our interface becomes like the one shown below,
We try to describe it step by step.



















When we first open our visual basic the appearance of the screen is like the one shown below




























Then; we have to make our menu bar.

Go to the tools from the menu bar, a small list opens where you have to select Menu Editor or
directly press Ctrl+E from the keyboard after doing so, a new window appears.





































If you want to add one more command you
should click on Next
When we want to delete a certain
command you should click on Delete
Insert is used to insert a new command
between two existing command.
After finishing that we see our menu bar
has already been created.


We shall use that same used for adding
many different commands. The process is
easy; the only difference is changing their
caption and giving them a new name and a
new caption.
The arrow to the write, is used when we want to do
grouping for commands which do changes in the same
pattern. For example if we have commands for changing
the text color, we shall group them under a (Font color)
so Red, Blue..etc. all must be placed under Font Color.
In the Space provided for the Caption,
we are going to write the name of the
command which we want to appear on
our menu.
In the Space provided for Name, we
are going to write the name of our
command like the one shown below
































Private Sub Exit_Click()
End
End Sub
Private Sub Times_New_Roman_Click()
Text1.FontName = Times_New_Roman.Caption
End Sub

Private Sub Verdana_Click()
Text1.FontName = Verdana.Caption
End Sub
Private Sub fs12_Click()
Text1.FontSize = fs12.Caption
End Sub
Private Sub fs18_Click()
Text1.FontSize = fs18.Caption
End Sub
Private Sub fs24_Click()
Text1.FontSize = fs24.Caption
End Sub
Private Sub Red_Click()
Text1.ForeColor = vbRed
End Sub

Private Sub Blue_Click()
Text1.ForeColor = vbBlue
End Sub

Private Sub Green_Click()
Text1.ForeColor = vbGreen
End Sub
The same process must be repeated,
after finishing the step of writing codes
start which is quiet easy.

















































Private Sub Left_Click()
Text1.Alignment = 0
End Sub

Private Sub Right_Click()
Text1.Alignment = 1
End Sub

Private Sub Center_Click()
Text1.Alignment = 2
End Sub
((Every human being can fall in faulty. The best of those who fall in faulty
is the one whom makes repentance))

,,.t- :,, , : l,- _tt i, .jt,. , at :,l i,
, .- _. j t , .,.j,., i,. j ,, t _.,t: .j.
i,, t _t,ji- , .j,,.- i ,, _tj. .,. :.,.,tt., i.tjit.
. , .j,.- _t,,t ..- ,,.t- , i.tji, , _, .t.t ,..
t _,,l ,,-t tt t, .t- i.t,-:,t , .-
_t, ,,-t ,., , :,. v t,. a,,,-t _.,. , t,j
t , a,tl,l , .tt. , :j, l .l , , .:, - , _t
., ,, ..: ,. l. t, ._,: .:t , :,.j: ,. _
.,,tt ..t,jti,i , :,,, ..: .t, ,,-t i,. t ,,
t, , ,_t-,l , :i , ; _.j ..: t , it. , .- _.t.
..,,: tl

Note Pad





















You must draw the interface of
the program as shown beside,
doing this is quiet easy, we have
some Check Boxes and Option
Buttons, Two Text Boxes and one
Label.
There is no any thing new in
creating an interface all you have
to do is to change the captions of
the check boxes and the option
button to the required name.

Changing the captions of the
check boxes and the option
buttons are just like changing the
caption of a label.
Go to the property of Check
Box/Option Button and change
the caption to the desired name.
If we want some action to
automatically take place as we
press the Run Button we have to
write codes in the First form or
the form which comes first.

Private Sub Form_Load()
Label1 = "Notepad": Text1 = "":
Text2 = ""
End Sub

The coded which is written above
tells the program to delete what
ever is written in the Text1 and
Text2 so
When the program is first Run
Text1 and Text2 will contain
nothing.
Private Sub Check1_Click()
If Check1 = Checked Then
Text1.FontBold = True
Else
Text1.FontBold = False
End If
End Sub
Private Sub Check2_Click()
If Check2 = Checked Then
Text1.FontItalic = True
Else
Text1.FontItalic = False
End If
End Sub

















































Private Sub Check3_Click()
If Check3 = Checked Then
Text1.FontUnderline = True
Else
Text1.FontUnderline = False
End If
End Sub
Private Sub Option1_Click()
Text1.FontSize = Option1.Caption
End Sub
Private Sub Option4_Click()
Text1.BackColor = vbRed
End Sub
Private Sub Option7_Click()
Text1.ForeColor = vbBlue
End Sub
Private Sub Check4_Click()
' Font Color by using QB color
On Error Resume Next
If Text2 < 0 Or Text2 > 15 Then
MsgBox "Enter Number between ( 0 and 15 )"
End If
If Check4 = Checked Then
Text1.ForeColor = QBColor(Text2)
Else
Text1.ForeColor = 1
End If
End Sub

Electronic Exam

Draw the interface as shown below


























Private Sub Command1_Click()
If Text1 = "" And Text2 = "" Then
MsgBox "please write your name and your group to enter"

Else
Form2.Show
Unload Me

End If

End Sub
Private Sub Command2_Click()
Unload Me

End Sub

The interface of the second form must be like the one shown below.



We only write code for the correct choice.




















Private Sub Check1_Click()
If Check1 = Checked Then
Form6.Label4 = Check1.Caption
Else
Form6.Label4 = ""

End If

The interface of the third form must be like the one shown below.




















Private Sub Command1_Click()
Form4.Show
Unload Me

End Sub
Private Sub Check2_Click()
If Check2 = Checked Then
Form6.Label6 = Check2.Caption
Else
Form6.Label6 = ""

End If
End Sub










The fourth form is coded as shown below















Private Sub Command2_Click()
Form2.Show
Form6.Label6 = ""
Unload Me

End Sub
Private Sub Check1_Click()
If Check1 = Checked Then
Form6.Label8 = Check1.Caption
Else
Form6.Label8 = ""
End If
Private Sub Command1_Click()
Form5.Show
Unload Me
End Sub










The fifth form must be coded as shown below














Private Sub Command2_Click()
Form6.Label8 = ""
Form3.Show
Unload Me

End Sub
Private Sub Check2_Click()
If Check2 = Checked Then
Form6.Label10 = Check2.Caption
Else
Form6.Label10 = ""

End If
















The interface of the sixth form must be like the one shown below.








Private Sub Command1_Click()
Form6.Show
Unload Me

End Sub
Private Sub Command2_Click()
formm6.Label10 = ""
Form4.Show
unlaod Me

End Sub




















































Private Sub Command1_Click()
i = 0
If Label4.Caption = Label5.Caption Then
i = i + 1
Else: i = i
End If
If Label6.Caption = Label7.Caption Then
i = i + 1
Else: i = i
End If
If Label8.Caption = Label9.Caption Then
i = i + 1
Else: i = i
End If
If Label10 = Label11 Then

i = i + 1
Else: i = i
End If
Label12.Caption = i

((Beware! There is a piece of flesh in the body if it becomes good
(reformed) the whole body becomes good but if it gets spoilt the whole
body gets spoilt and that is the heart))




, l. _: _ ., _,, _,t :,. _j.l _,t. ,j,tt _t,- ,

Bending Test in Simply Supported Beams

This test is one of the most important application that ever made for the students of second class
because from this test you will be able to build up many different applications for solving many of
your equations.























First of all you have to draw this interface its
clear that the interface made of several Labels
and Combo box.
You have previously learned that if we want to
add some (value) to Combo boxes we must inter
these value in to the form load in this way
Private Sub Form_Load()
Combo1.AddItem "1000"
Combo2.AddItem "20"
Combo3.AddItem "5"
Combo4.AddItem "2.5"
Combo4.AddItem "5"
Combo4.AddItem "7.5"
Combo4.AddItem "10"
Combo4.AddItem "12.5"
Form2.Show
End Sub
You notice that we have written
((Form2.Show)) in the form load of the first
form. Doing this will allow the second from to
be shown together with the first form when we
run the program.
Combo boxes have Text instead of Caption, so if we want the combo box to show us
whatever we want while in run mode we have to change the Text of the Combo Box
which is found in the property window if the Combo Box.
All the text of the other combo boxes are changed by changing their names in their
property window.





















































Private Sub Command1_ClIck()

If Text1 = "" Then
MsgBox "Enter the Value of Deflection"
Else
Form2.List1.AddItem Combo4
Form2.List2.AddItem Text1

' I = b*h^3/12
I = Combo2 * Combo3 ^ 3 / 12

' Modulus of Elasticity = Load * Span / (48 * I * Deflection)
E = Combo4 * Combo1 ^ 3 / (48 * I * Text1)
Form2.List3.AddItem E

' Rotation = Load * Span ^ 2 / (16 * E * I)
Form2.List4.AddItem Combo4 * Combo1 ^ 2 / (16 * E * I)

' Curvature = 1 / Deflection
Form2.List5.AddItem 1 / Text1

' Moment = Load * Span / 4
Form2.List6.AddItem Combo4 * Combo1 / 4

End If

End Sub
The deflection ha a Text Box named Text1.
So the amount of Text Box is entered while we are in
Run Mode

The interface of the second form should be like the one shown below.





































((Who does not show mercy, no mercy would be shown to him by Allah))


,,- _, _tj, :, ,t .,,,tt _t,.t.t. ji, )t,

Electronic Exam

In this lecture we are building up an electronic exam and we are going to use on of the most
important command which is called Timer.
Through using the timer, the program automatically changes the forms until we reach the last form.
This type is used allover the world in electronic exams.

















Private Sub Timer1_Timer()
Form2.Show
Unload Me
End Sub
Private Sub List1_Click()
Form5.List1.List(0) = List1
Form2.Show
Unload Me

End Sub
For entering the letters in to the list we must write codes in the form as shown below
Private Sub Form_Load()
List1.AddItem "A"
List1.AddItem "B"
List1.AddItem "C"
List1.AddItem "D"

For the second form, we write the codes as shown below























Private Sub List1_Click()
Form5.List1.List(1) = List1
Form3.Show
Unload Me

End Sub
Private Sub Timer1_Timer()
Form3.Show
Unload Me
End Sub
Private Sub Form_Load()
List1.AddItem "A"
List1.AddItem "B"
List1.AddItem "C"
List1.AddItem "D"

End Sub

The codes for the third form must be written as shown below























Private Sub List1_Click()
Form5.List1.List(2) = List1
Form4.Show
Unload Me

End Sub
Private Sub Timer1_Timer()
Form4.Show
Unload Me
End Sub
Private Sub Form_Load()
List1.AddItem "True"
List1.AddItem "False"

End Sub

The fourth form must be coded as shown below























Private Sub List1_Click()
Form5.List1.List(3) = List1
Form5.Show
Unload Me
End Sub
Private Sub Timer1_Timer()
Form5.Show
Unload Me
End Sub
Private Sub Form_Load()
List1.AddItem "True"
List1.AddItem "False"
End Sub
The last form must be coded as shown below


























Private Sub Timer1_Timer()
i = 0
If List1.List(0) = List2.List(0) Then
i = i + 1
End If
If List1.List(1) = List2.List(1) Then
i = i + 1
End If
If List1.List(2) = List2.List(2) Then
i = i + 1
End If
If List1.List(3) = List2.List(3) Then
i = i + 1
End If
Text1 = i
Text2 = i * 25

End Sub




















































Private Sub Form_Load()
List2.AddItem "A"
List2.AddItem "A"
List2.AddItem "True"
List2.AddItem "True"
Form5.BackColor = QBColor(4)
Label1.ForeColor = vbRed
Label2.ForeColor = vbRed
Label1.FontBold = True
Label2.FontBold = True


End Sub
Private Sub Command1_Click()
Unload Me

End Sub

((One f the sayings of the early Prophets which the people have got is : If
you dont ashamed, do whatever you like))


, :,-i,,.: i.t-t , , ;,,, .t,,t t a,t .t. ..- . -.
. _j:,l ,:, ;, ,t ,. .t. .:,-,, _i, ,, a, i: ,t,t
_.,,: _t,,,

Dictionary
In this lecture we are going to make a dictionary.

Draw the interface as shown below

As it clear form the interface we need three list boxes for writing the words in them, and one text
box in which we write the word which will be translated.

























These codes must be written in the form load.
Private Sub Form_Load()
List1.AddItem "Hurry"
List1.AddItem "Go"
List1.AddItem "Name"
List1.AddItem "University"
List2.AddItem "Isra3"
List2.AddItem "Izhab"
List2.AddItem "Ism"
List2.AddItem "Aljami3a"
List3.AddItem "Xearaka"
List3.AddItem "Bro"
List3.AddItem "Nau"
List3.AddItem "Zanko"
Label1.FontSize = 24
Label1.FontBold = True
Label1.ForeColor = vbGreen
Form1.BackColor = QBColor(3)

End Sub
In this program we are writing the codes in the text box as shown below





List1.ListIndex = List2.ListIndex

This sentence which is written in
Read color is very important
If you forget it, the program will
Not work properly.






































Private Sub Text1_Change()
For i = 0 To List1.ListCount - 1
List1.ListIndex = i
If Text1 = List1 Then
List3.ListIndex = i
List2.ListIndex = i
End If
Next i
List1.ListIndex = List2.ListIndex

End Sub

((the one who direct people to do good works is regarded as a person how
has committed it))


,.i, :,.. , _, _.i,t. :,tt- t ..


Converting Binary numbers to Decimal

The interface of the program should be like the one shown below




























Before describing how to write the codes to convert binary in to decimal, we shall describe a
new method which is used to add numbers, texts to a certain list.

You know that previously we if we wanted to add numbers to a certain list, we did it from the
form load by this method
List1.additem 1
But now you are going to learn a new method which is very important and is more practical.

Private Sub Command2_Click()
Dim EnterList As String
EnterList = InputBox("Binary Number", "Binary to Decimal")
List2.AddItem EnterList
End Sub
Private Sub Command3_Click()
On Error Resume Next
List2.RemoveItem List2.ListIndex
End Sub
Private Sub Command4_Click()
On Error Resume Next
List2.Clear
End Sub














































Private Sub Form_Load()
For i = 7 To 0 Step -1
List1.AddItem 2 ^ i
Next i
End Sub
Private Sub Command1_Click()
Sum = 0
For i = 0 To List1.ListCount - 1
If List2.List(i) = 1 Then
Sum = Sum + List1.List(i)
'Else
'Sum = Sum
End If
Next i
Text1 = Sum
End Sub
((the believer does not provide opportunity to be stung twice form
one (and the same) hole))

::t,, .
...,, , :,l i, , . ,,.,,, i,tt , tttt. t i,
. t., tttt ij, t , t t,tt.,l , jtt, j,t. _jtt,
ijt,tt.,l _j,,,
.,, , l. . i,. ,:,j,,, , .,.t., ", tt," :,jtt, ;
t tt, , tj _jtt. , _- _t,, , .,,: i,.i


Converting Decimal to Binary

The interface of the program should be like the one shown below




































Private Sub
Form_Load()
For i = 7 To 0 Step -1
List1.AddItem 2 ^ i
Next i
End Sub

The above code is
written in the form
load so that numbers
starting form 128 to 1
appears on the first
list1.


Private Sub
Command1_Click()
List2.Clear
For i = 0 To
List1.ListCount - 1
If Val(Text1) >=
List1.List(i) Then
List2.AddItem 1
Text1 = Text1 -
List1.List(i)
Else
List2.AddItem 0
End If
Next i
End Sub

((Be constant conscious of Allah wherever you have been. And do
perform good deeds immediately after doing evil deeds so that they
destroy them. Treat people in a good manner))


:jt i "tt," t aj _.,,. .,.i: tjt.
, _tt t ..: , i, "it" tl: t l,- :,t j _j, j _.,,.,.
i,,i _t,, _.,,, tr,-

































Private Sub Command1_Click()
Dim EnterList As String
EnterList =
InputBox("Number",
"Number")
List1.AddItem EnterList
End Sub

Private Sub Command2_Click()
On Error Resume Next
List1.RemoveItem
List1.ListIndex
End Sub

Private Sub
Command3_Click()
On Error Resume
Next
List1.Clear
End Sub

Private Sub Command4_Click()
For i = 0 To List1.ListCount - 1
For j = 0 To List1.ListCount - 1
If Val(List1.List(i)) >
Val(List1.List(j)) Then
Temp = List1.List(i)
List1.List(i) = List1.List(j)
List1.List(j) = Temp
End If
Next j
Next i
End Sub

Private Sub Command5_Click()
For i = 0 To List1.ListCount - 1
For j = 0 To List1.ListCount - 1
If Val(List1.List(i)) <
Val(List1.List(j)) Then
Temp = List1.List(i)
List1.List(i) = List1.List(j)
List1.List(j) = Temp
End If
Next j
Next i
End Sub

((Allah loves those whom perform their works in a perfect way))

.,. . ,. ;tt, ,:,,, ..: _t, ,,-t ,:,,,j, i,
.j,t. ..: _,t "tt," t t, :,j,j.

In this lecture, we are going to link between Microsoft Excel and Visual Basic

In our case, the interface of the program should be like the one shown below


























Private Sub Form_Load()
List1.AddItem "2"
List1.AddItem "4"
List2.AddItem "5"
List2.AddItem "8"
End Sub
Private Sub Command1_Click()
Dim ew As Workbook
Set ew = Workbooks.Open("D:\visulal
basic\f\f.xls")
With ew
For i = 0 To List1.ListCount - 1
.Sheets(1).Cells(i + 2, 1).Value = List1.List(i)
.Sheets(1).Cells(i + 2, 2).Value = List2.List(i)
Next i
For i = 0 To List1.ListCount - 1
List3.List(i) = .Sheets(1).Cells(i + 2, 3).Value
Next i
.Close Savechanges:=True
End With

This is the path were the visual basic
file and the excel file are saved.
Its strongly recommended for the
visual basic file and the excel file to be
saved in the same folder otherwise the
program may not work properly













































Its clear from the pictures, you should go to Microsoft Excel, make the same table as shown
above, Know that you must not enter the given data of Length and Width in Microsoft excel
because those data had already been entered in to the lists of Visual Basic, the program
automatically sends it to Microsoft Excel and the calculation in done in Microsoft excel and
the result is returned to Visual Basic
But you have to write the formula of the calculation in Microsoft Excel as shown in the
figure above.

((None of you will have faith till he wishes for his (Muslim) brother what he
likes for himself))

" ,s ;. a,t .:,t, , ., _t,..j,, ",s _.tt :,i).j,, , :,, j t _
t. .:,t _tj ,.j: .i tt. _tj ,:,,.,.: :,-i,:, _tjit. , ,.,
:,i).j,, ,. t., ,.jt, i.,.i , _t, _tj,i).j,, i,, t:
t,- _. ,. :,,., j _.j,, ,. _.tjt j ,s t ,. ),. :j
t,- j ,r _,s , .j,l: ._
Desktop

In this lecture we are going to build up a program which we can call a new window, it will work as
a window.
The appearance of the program must be like the one shown below



Dont worry; we are going to describe how to make such a program step by step.

















((Do no have a dispute with your (Muslim) brother. Do not make joke to
him that he dislikes. And do not promise that your cannot fulfill))

When you open the Visual Basic a window will be opened to you as shown below






























,, ,,.r l,- _.t .: t a,j a:,t _: , t,t. _ ..tt.
: j , :t,. _,t , t,t. _j,l , ,,.r l,- ,t a:, tt:,t
t t., ,_,, _t-t, :,,. ...jtjt. j , ..t , ;i.. _.,r t _t
_it,.. t-, ;. _j,.s- _t,. ,, ji:,t _t,.ij, _,,i, i, ._t-
-t ,t _jtt,jt , t.t _tt,j ,,-t ,tt, ,t,. _.i,, ,,.r _t
. , .,, ,t _,, , tt, :,:

First of all we must bring one image on to the screen and increase its size until it will cover the
whole screen

Increase the size of the image until it will cover the whole screen

After that you must go to the property window of the image where you have to change the Stretch
property to true
As shown below








Then we must select on the picture property, a new window will
show up where we have to select the photo which we want as the
background of our window as shown below
In the (Load Picture) window we must find a photo and click on the
open button to make it our background.


In this case we have selected the photo of this very beautiful horse.
Then you have to repeat this process but this take for some small icons,
Draw an image, go to properties and change its Stretch to True then from picture you will be able
to select the photo you want to bring in to your new window.

You must also be aware of one important point, when you design a window you must save the
visual basic project and form file in to a certain folder and which image you want to put in the
window program must previously have been put in that folder.


















All the picture that we put in our program must be putted in the save folder that contains the visual
basic project and form file.
In our case, we have putted all the pictures and the files of visual basic in a folder names Desktop.

Now we will discuss how to crop images to the desired size
There are many methods used to crop an image but Microsoft Office Picture Manager is one of the
most powerful and easy program with which we can crop our pictures.

The picture below shows how to open the program


















After opening the program, copy your picture and paste
it in the program.
When you paste your picture it will be shown in a small
square as shown

Then click on Edit
picture as shown by the
read arrow.
Then click on crop as shown below

After that you can crop the image by dragging
on one of its corners.



















































The picture can
be cropped by
holding left
mouse button on
one of its corner
to the desired
view
As illustrated in
the picture
Finally click on ok and your picture will be cropped.
i,t. ,.i:,t, ,. tt:,t . ,,,, , i,-:t
.j,t , ., : ,..._j: ijt, _i:,:.j , a:
t t ,-. _j . ,l _jv t _t, _.t,:,,- .
t.r t :,. _, , :,:.:,i, ,, ,. , tj , ,.,,,,, i.t
_t,t, ,i.tj _.t.,.: , it , .tt _j:, ,
,l _. :-, ,-i,...j: _t:. t:t. _.i:
t, ,.t-. ,,-t.. t _ t t,t : :,. .
r , _.,t.: tt _.t.,.: , it j a. ,
t.i, j :_:j , _




























You must crop all the required images and save them in the folder which you have saved
the project and the form file of the visual basic.
After that you must bring your screen to the desired interface after doing so, the last part of
the work starts which consists of writing codes for the program.












Private Sub Image6_Click()
Shell "shutdown -s"
End Sub
Private Sub Image7_Click()
Shell "shutdown -r"
End Sub
Private Sub Image8_Click()
Shell "shutdown -l"
End Sub
Private Sub Image2_Click()
Shell "C:\Program Files\Microsoft Office\OFFICE11\winword.exe"
End Sub















































Private Sub Image3_Click()
Shell "C:\Program Files\Microsoft Office\OFFICE11\excel.exe"
End Sub
Private Sub Image4_DblClick()
Shell "C:\Program Files\AutoCAD 2007\acad.exe"
End Sub
Private Sub Image5_DblClick()
Shell "C:\Program Files\Microsoft Visual Studio\VB98\VB6.exe"
End Sub
Private Sub Timer1_Timer()
Text1 = Time
Text2 = Date
End Sub
_.tj ,t _j,,, _ "" _.t j,, :,l i, , _ a. ,_jjt
,, . t,, ,, ajt,t , _jt,, :, . , _t-.tj _. . _t-, t .tj ;
_jt, , l,l , _. jt- , it. t ",," _i,,. t "" l. t, ..
" .,":t, "_."_tj l _,t.,r j.i,t i,. ,.,,itt . i.tq
,, , t . , , .j , t ,. l. ;tt, ..j.,i "_:r" ,, t i,: _
i.tql " " _tj "..,," _i,,. t .,, a,.tql . . "" , i,
tj",t:,",tt, .j.t.i , ,- . l ,,, i i : , , t: _ _.tj
. .. : , t


Odd & Even















In this program, we are going to build up an
application that will automatically finds the sum of
the Even or the Odd numbers which we previously
have been entered in to a certain list through writing
codes in the form load.
After drawing the interface as shown beside, we have
to write a loop in the form load so that we will have
numbers starting from 1 to 11 in our first list box.
The code must be like the one shown below

Private Sub Form_Load()
For i = 1 To 11
List1.AddItem i
Next i
End Sub
Private Sub Command1_Click()
Sum = 0
For i = 1 To List1.ListCount - 1 Step 2
Sum = Sum + List1.List(i)
Next i
Text1 = Sum
End Sub
Private Sub Command2_Click()
Sum = 0
For i = 0 To List1.ListCount - 1 Step 2
Sum = Sum + List1.List(i)
Next i
Text2 = Sum
End Sub

You might also like