Visual-Basic-1
Visual-Basic-1
1-Introduction
Hundreds of high-level languages have been developed, but only a few have achieved broad
acceptance, for example (QBASIC, FORTAN and Pascal). Visual Basic is an example of a
graphical-based language. A graphical-based language allows the user to work directly with graphics.
Visual Basic is derived from the “visual” term refers to the method used to create the graphical
user interface (GUI), Simply drag and drop prebuilt objects into place on screen without having to
learn an additional software package. The “Basic” term refers to the BASIC (Beginners All-Purpose
Symbolic Instruction Code) language, a language used by more programmers. Visual Basic has
evolved from the original BASIC language and now contains several hundred statements, functions,
and keywords, many of which relate directly to the windows GUI. Beginners can create useful
applications by professionals to accomplish anything that can be accomplished using any other
windows programming language.
Visual Basic is a Microsoft Windows Programming language. Visual Basic programs are created
in an Integrated Development Environmental (IDE). The IDE allows the programmer to create, run
and debug Visual Basic programs conveniently. IDEs allows a programmer to create working
programs in a fraction of the time that it would normally take to code programs without using IDEs.
The New Project dialog allows the programmer to choose what type of Visual Basic program to
create. Standard EXE, which is highlighted by default, allows the programmer to create a standard
executable. Each type listed in Fig.(2-2) describes a group of related files called a Project.
1
Mathematics and computer Applications Department-Third Class Visual Basic
Project is a program designed to user application that may be simple (like calculator
program) or complex (like word program). The project types listed in Fig.(2-3) are the “Visual”
in Visual Basic, because they contain predefined features for designing Windows programs.
The project is a collection of files that makes the user program. They may consist of form,
modules, active x controls.
• Recent: opening a project that has been previously loaded into the IDE.
Figure (2-3) shows The IDE after Standard EXE is selected. The top of the IDE window
(the title bar) displays “Project1-Microsoft Visual Basic [design]”.The environment consists of
various windows when Visual Basic is started (by default):
Menu Bar
Project
Explorer
Tool Bar
Form
Properties
Toolbox Controls Window
Fig. (2-3)
2-2-1 Project1-Form1 (Form): window contains a form named Form1, which is where the
program’s Graphical User Interface (GUI) will be displayed. A GUI is the visual portion of the
program, this is where the user enters data (called inputs) to the program and where the
program displays its results (called outputs) .We refer to the Form1 window simply as “the
form”. Forms are the foundation for creating the interface of an application. You can use the
forms to add windows and dialog boxes to your application. You can also use them as container
for items that are not a visible part of the application’s interface. For example, you might have a
form in your application that serves as a container for graphics that you plan to display in other
forms.
2
Mathematics and computer Applications Department-Third Class Visual Basic
2-2-2 Toolbox Controls: Contains a collection of tools that are needed for project design as shown in
Fig.(2-4). To show the toolbox press View> toolbox icon. The user can place the tool on form, and
then work with the tool. To place the tool on form: click on tool>draw tool to form > the tool appears
on form or double click on tool then the tool appears on form. Table (1) summarizes the toolbox
controls.
Pointer PictureBox
TextBox
Label
Command Button
Frame
Option Button
checkbo
ListBox
Combobo
VScrollB
HScrollB
DriveListB
Timer
File
DirListBox
Line
Shape
Date
Image
OLE
Fig.(2-4) Toolbox Window.
3
Mathematics and computer Applications Department-Third Class Visual Basic
The tools in tool box are divided to many categories according to their functions:
First The control tools: there are three different tools that are used for control (as switches):
Command Button: used as a switch (such as Ok or/and Cancel) buttons. Code is written
in the click event procedure of this tool.
Option (Radio) Button: For selection as a group. Many option is placed inside
container (a Frame control), one control is selected from the group all others of the
group are automatically deselected.
Check Box: For a yes/no (true/false) selection. Used as individuals (not grouped). It
may be selected more than one check control at same time.
a) Text Box: For text edit, like Note Pad, it can be single line or multi lines. Box takes
any size.
b) List Box: for a list, user adds to and deletes from this list. It takes any size.
c) Combo Box: consist of (list and arrow, when clicked a small list appears), if user
selects item from the list, it will be displayed in text box. Vertical size is fixed.
d) Label: Fixed text appears on form for remark.
Third Container Tool: is a frame tool, which used to grouped many other tools. It is important
in the application's interface design.
Picture Box: used to display images, and used to output any type of data
(numeric, string, …ect.) .
Image: used instead of picture box because it consumes fewer system resources, but used
only to displays the images in strech style.
Shape: used only to display rectangles, circles and ovals on the forms. Never contains any
events.
Line: used only to display lines. Never contains any events.
DriveListBox: it is a special list box filled automatically with derives (HardDisc, Floppy,
CD) in the system. It is an invariant.
DirListBox : it is a special list box filled automatically with folders in the selected derive in
DriveListBox tool. It is a list invariant.
FileListBox : it is a special list box filled automatically with the names of files in the selected
folder in DirListBox tool. It is a list invariant.
4
Mathematics and computer Applications Department-Third Class Visual Basic
Seventh Data Tool: used as an user interface with an databases applications, that built in one of the
database management systems (DBMS) like Microsoft access.
The following table shows the default properties of the basic tools:
2-2-3 Properties Window: The properties window displays the properties for a form or control.
Properties are attributes such as size, position, etc. like a form; each control type has its own set of
properties. Some properties, like width and height, such as, are common to both forms and controls,
while other properties are unique to form or control. Controls often differ in the number and type of
properties. Properties are listed either alphabetically (by selecting the alphabetic tab) or categorically
(by selecting the categorized tab). The most important properties of the objects in general are listed in
the following table. To show the properties window press View> properties window icon.