Lec1 PDF
Lec1 PDF
Lec1 PDF
1
Visual Basic 6 Programming : Lecture 1 By: Zinah Hussein
With VB 6, you can create any program depending on your objective. For
example you can create educational programs to teach business, economics,
engineering, computer science, accountancy, financial management,
information system and more to make teaching more effective and
interesting.
2
Visual Basic 6 Programming : Lecture 1 By: Zinah Hussein
2- All visual programs follow the same concepts, therefore the user will
become more familiar with visual approach for other visual languages.
3- It provides Input box and Output box as an interactive windows with
user.
4- It is able to connect to Internet, and to call Explorer.
Before you can program in VB 6, you need to install Visual Basic 6 in your
computer. On startup, Visual Basic 6.0 will display the following dialog box
You can choose to start a new project, open an existing project or select a list
of recently opened programs. A project is a collection of files that make up
your application. There are various types of applications that we could create;
however, we shall concentrate on creating Standard EXE programs (EXE
means executable program). Now, click on the Standard EXE icon to go into
the actual Visual Basic 6 programming environment.
3
Visual Basic 6 Programming : Lecture 1 By: Zinah Hussein
To exit from Visual Basic and return to Windows is like exit from most
Windows applications. There are three ways to close the Visual Basic as
stated below.
1- Click on close button icon that appears in the upper-left corner of the
screen.
2- Press Alt+F4
3- Select File >Exit
The IDE (integrated development environment) consists of many elements.
Some elements are displayed when Visual Basic is started (By default) as in
the following figure. Other elements are displayed if the user requires them.
We will list some of these elements.
4
Visual Basic 6 Programming : Lecture 1 By: Zinah Hussein
f. Project Explorer Window: it is a list of the forms and modules for the
current projects. It is a hierarchical tree- branch structure, where the
project at top of tree and other parts like forms ,modules) descend from
this tree.
g. Form Layout Window: The Form Layout window is a small screen.
Which is used to reposition the form of the application so that it appears in
proper place when project is run.
5
Visual Basic 6 Programming : Lecture 1 By: Zinah Hussein
1. The Main Window consists of the title bar, menu bar, and toolbar. The
title bar indicates the project name, the current Visual Basic operating
mode, and the current form. The menu bar has drop-down menus from
which you control the operation of the Visual Basic environment. The
toolbar has buttons that provide shortcuts to some of the menu options.
The main window also shows the location of the current form relative to
the upper left corner of the screen (measured in twips) and the width and
length of the current form.
6
Visual Basic 6 Programming : Lecture 1 By: Zinah Hussein
4.
7
Visual Basic 6 Programming : Lecture 1 By: Zinah Hussein
8
Visual Basic 6 Programming : Lecture 1 By: Zinah Hussein
9
Visual Basic 6 Programming : Lecture 1 By: Zinah Hussein
6. The Project Window displays a list of all forms and modules making up
your application. You can also obtain a view of the Form or Code
windows (window containing the actual Basic coding) from the Project
Window.
Code Editor Window: Code Editor Window is used to write a VB code for
an application. For each form there is a separate code editor window. It is
displayed when user clicks on form or object in form.
10
Visual Basic 6 Programming : Lecture 1 By: Zinah Hussein
To Create an Application:
The title of program includes the name of project, and when the user first
starts the program it takes a defaulted value (project1). The following steps
are required to create an application in Visual Basic 6.0:
1) Select type of project New or Exciting. A form automatically appears in
the form design .The basis for any application's interface is the form that
user should create. User can add other forms to the project (to add another
form select project menu>add form).
2) To add objects (controls) to the form use the ToolBox.
3) Set the properties for the objects through properties window.
4)Write code. The Visual Basic Code consists of statements, and
declarations. The code for an application can be written on the Code Editor
window. In this window user can view and edit quickly any of the code.
5) Run the Application. To run the application, click the Start button on the
toolbar, or press F5.
6) Stop. To stop running the application and return to visual basic program
click on stop button in tool bar.
7) Check if there is an error, return to step 3 ,otherwise continue.
8) Save project.
9) Exit
11
Visual Basic 6 Programming : Lecture 1 By: Zinah Hussein
Example1: Design a form with one text box and two Commands button.
Write a code so when run project and click on command1 (My
Name) replace the word in text box to (Ahmed), and when click
on Command2 (Close) terminate the program and return back to
the form interface.
Solution:
12
Visual Basic 6 Programming : Lecture 1 By: Zinah Hussein
• The Caption property determines what is displayed in the form‟s title bar
or what text the controls displays on a form.
• The TextBox‟s Text Property determines what text (if any) the TextBox
displays.
• The Name property identifies a form or control. It‟s necessary only for
writing code.
13
Visual Basic 6 Programming : Lecture 1 By: Zinah Hussein
The Code :
Command Button1:
Text1.text=”Ahmed”
End Sub
Command Button2:
End
End Sub
Saving a Project :
Choosing save project from the file menu. Visual Basic will prompt you
separately to save the form and then the project.
14
Visual Basic 6 Programming : Lecture 1 By: Zinah Hussein
Example 2: Design a form shown in figure below, with three text boxes and
one Command Button. Write code in the Command1 (Execute).
So when run project enter the Student Name in TextBox (Txt1)
and the Father Name in TextBox (Txt2). When click on
Command1 (Execute) replace the Full Name in the
TextBox(Txt3).
5. Adding a Command Button1 to the form. Click on button and draw Button
to form then the Button1 appears on form1.
15
Visual Basic 6 Programming : Lecture 1 By: Zinah Hussein
The Code :
Command Button1:
Command Button2:
Private Sub Command2_click ( )
End
End Sub
16
Visual Basic 6 Programming : Lecture 1 By: Zinah Hussein
Saving a Project :
Choosing save project from the file menu. Visual Basic will prompt you
separately to save the form and then the project.
Example 2: Design a form shown in figure below, with three text boxes and
one Command Button. Write code in the Command1 (Execute). So when
run project enter the Student Name in TextBox (Txt1) and the Father Name
in TextBox (Txt2). When click on Command1 (Execute) replace the Full
Name in the TextBox(Txt3).
17
Visual Basic 6 Programming : Lecture 1 By: Zinah Hussein
Solution:
1. Adding a Label to the form1. Double-click the Label‟s Label to create a
Label with sizing handles in the center of the form1.
5. Adding a Command Button1 to the form. Click on button and draw Button
to form then the Button1 appears on form1.
18
Visual Basic 6 Programming : Lecture 1 By: Zinah Hussein
The Code :
Command Button1:
Text1.text=”Ahmed”
Text2.text=”Ali”
Text3.text=Text1.text+” ”+Text2.text
End Sub
19