Ahmed Ibra V.B
Ahmed Ibra V.B
Ahmed Ibra V.B
Introduction to MS-DOS :
MS-DOS (Microsoft Disk Operating
System) was the Microsoft-marketed version of
the first widely-installed operating system in
personal computers. It was essentially the same
operating system that (Bill Gates's) young
company developed for IBM as Personal
Computer - Disk Operating System in 1981.
Most users of either DOS system simply
referred to their system as Disk Operating
System. Like PC-DOS, MS-DOS was (and still
is) a non-graphical line-oriented command-
driven operating system, with a relatively
simple interface but not overly "friendly" user
interface. Its prompt to enter a command looks
like this:
C:\>
3.Structure information
4.System environment
1. Click Start.
2. Click Run.
3. Type cmd and press enter.
Otherwise, if you are using an older version of Windows, type command
into the Run box and click "OK". You could also type command.exe
6.MS-DOS Commands
1- Viewing the Contents of a Directory (dir)
C:\> dir
C:\>md test
The above example creates the "test" directory in the directory you are
currently in.
md c:\test
5- IP Configuration ( ipconfig )
Useful for troubleshooting your internet connection. Displays the current
IP address of your computer and the DNS server address. If you call your
ISP (Internet Service Provider) for reporting a bad internet connection, he
will probably ask you to run ipconfig.
To get your computers local network IP address, subnet mask, and default
gateway typing ipconfig alone will display this information as shown
below. Keep in mind this is only your local network information.
attrib +r
attrib +h
attrib -h
7- edit
Edit allows a user to view, create, and/or modify their computer files Edit
is only able to open a file with a maximum of 65,280 lines. If you are
running a MS-DOS version 4.x or lower or you are unable to find edit on
your hard disk drive.
8- type
TYPE [drive:][path]filename
9- copy
copy *.* a:
Copy all files in the current directory to the floppy disk drive.
copy myfile1.txt+myfile2.txt
10- cls
Cls is a command that allows a user to clear the complete contents of the
screen and leave only a prompt.
11- date
The date command can be used to look at the current date of the computer
as well as change the date to an alternate date. Date Display the current
date and prompt for a new one. If no date is entered, the current date will
be kept.
12- Rename
Used to rename files and directories from the original name to a new
name.
Note that you cannot specify a new drive or path for your destination.
Windows
1-Introduction
2- Windows7
* Mac OS is the trademark-protected name for a series of graphical user interface-based operating
systems developed by Apple Inc.
**client is an application or system that accesses a remote service on another computer system, known
as a server, by way of a network
*** Netbooks are a category of small, lightweight, and inexpensive laptop computers that omitted
certain features and offered reduced specification and computing power.
tablet PCs*, and media center PCs. Windows 7 cuts the fat from the Vista
release and promises to correct some of the wrongs found in the former
release. Vista started off on rocky terrain. Many of the accessories
commonly used on a desktop just wouldn’t work. It was months before
many manufacturers came out with compatible drivers for video cards,
printers, scanners, cameras, webcams, and the like. It’s these types of
problems that forced business owners to retain XP.
The terms 32-bit and 64-bit refer to the way a computer's processor
(also called a CPU), handles information. The 64-bit version
of Windows handles large amounts of random access memory (RAM)
more effectively than a 32-bit system. In simple terms, the data path on a
32-bit operating system is half the size of 64-bit operating systems. That
means that your computer can be slogging twice as much data around at
any given time with a 64-bit OS. In order for a 64-bit version of Windows
to be of value to you, you will also need a 64-bit processor and 64-bit
versions of the software that you plan to run. Without all three, you
would be wasting your time.
* tablet PC (tablet personal computer) is a portable personal computer equipped with a touch
screen as a primary input device.
2. Under System, you can view the system type.
1. Click Start.
• If you don't see "x64 Edition" listed, then you're running the
32-bit version of Windows XP.
The View Ruler icon works as a toggle button to turn the ruler on and
off.
To Drag and Drop Text:
• Select the text you wish to copy.
• Left-click your mouse and drag the text to the location you
wish it to appear. The cursor will have a text box under it
to indicate that you are moving text.
The following Topics will clarified online in the lecture using MS-word
program with data show device.
H.W:
Compose the following table where the columns and rows titles are
written with font type 'Arial' size 14 with bold effect in the center of the
table's cell. Also the cell width should be 15 units.
3-What is Windows 7?
Windows 7 is the next version of Microsoft Windows Operating System (OS).
Windows 7 was released to manufacturing on July 22, 2009, and reached
general retail availability on October 22, 2009, less than three years after the
release of its predecessor, Windows Vista.
1
3- A new accessibility feature is the Windows Key plus (+) key
gives the screen an instant zoom like the second Google search picture,
and the minus key (-) returns the resolution to the normal size like the
first Google search picture.
3
6- Comparisons between Win 7 and Win Vista
4
4- Peek gives you the power of X-ray vision, so you can peer past all your
open windows straight to the Windows 7 desktop. Simply point to the end
of the taskbar and watch open windows instantly turns transparent).
Snap is a quick new way to resize open windows, simply by dragging
them to the edges of your screen. Shake is to quickly minimize every
open window except the one you're shaking. This feature can save you
time if you want to focus on a single window without minimizing all your
other open windows one by one. You can then restore all of those
windows by shaking the open window again. Pictures below show Peek
and Shake features respectively.
Peek in windows 7
5
Shake in windows 7
5- Smarter search. Type in the Start menu search box and you'll see results
instantly, grouped by category: documents, pictures, music, e-mail, and
programs.
6- Search in a folder or library and you can fine-tune your search with filters
like date or file type; and use the preview pane to peek at the contents of
your results. See the pictures below.
6
7- Easy sharing with Home Group. Sharing files and printers on your
home network should be simple. Connect two or more PCs running
Windows 7, and with a minimum of fuss you can start sharing music,
pictures, videos, and documents with other people in your home.
8- Built for speed. Windows 7 has key performance improvements to take
up less memory and run background services only when you need them.
It's designed to run your programs faster and to sleep, resume, and
reconnect to wireless networks quicker.
9- Better wireless networking. Connecting to wireless networks on your
laptop just by a couple of clicks. Choose from the list of available
networks in the taskbar, click one, and then connect. Once you've
7
8- Versions of Windows 7
Windows 7 Enterprise, Windows 7 Home Professional, Windows 7 Home
Basic, Windows 7 Home Premium, Windows 7 Ultimate and Windows 7
Starter.
Copy and Paste operations of files from the source to destination locations are
very important features in windows. In this section, you will learn how to copy
and paste any type of file (s) to a new folder. Let's start by creating a new folder.
1- Start the Windows 7 Explorer by clicking its icon to the right of the Start
button (Circled by the black line):
9
3- Create a folder by clicking the New Folder button at the top:
10
The blue highlight means that you can go ahead and type a new name for
that folder. In the New folder below, we've changed the name to University
of Technology:
If you've clicked away from the new folder, click back on to it once with
your left mouse button. Pause for a second or two and then click again
with your left mouse button. It should turn blue again. If it doesn't, right
click the new folder and select "Rename" from the menu that appears (if
you need to rename it again).
Now that you have a new folder called University of Technology folder,
you need to add file (s) to it.
5- Use the Navigation pane on the top to navigate to a location on your
computer where you have file (s). In the Desktop, we've found some files
that need to be copied to the C:\University of Technology folder. (If you
11
have files on a USB stick or data card, insert it and then click Computer.
Your USB stick or data card should show up there as a drive.)
6- Once you've found some files, select the ones you want to add to your
C:\University of Technology folder. To select one file, simply click it
with your left mouse button. To select more than one file, hold down the
left CTRL key on your keyboard. With the CTRL key held down, click
each file you want to add. If you've made a mistake, click the file again to
deselect it.
Once you have selected your files, right click on any of them. From the
menu that appears select Copy:
12
7- Now navigate back to the University of Technology folder you have just
created in the C:\. Double click the University of Technology folder to
move inside of it. You should see a message on the right saying "this
folder is empty". Right click anywhere inside of the big white area, and
right-click again. From the menu, select Paste.
8- The files will be copied and pasted over to the University of
Technology folder as follow:
13
14
9- To delete file (s) using windows, just select any file (s) that want to
be deleted using the same procedure described above, then Right click
From the menu select Delete operation. For example, consider the
following pictures that show you how Delete is working under windows:
15
1- Introduction
Word 2007 is the greatest word processing application from Microsoft. It is
used for creating basic letters to more complex documents like newsletters,
manuals, forms. Known as a Graphical User Interface (GUI) it uses windows,
icons, pull-down
down menus, and the mouse to make using
using the program easier to
learn.
It is recommended that during the installation of Office 2007 you also uninstall
your older version(s) of Office (like Office 2003).. Although you can have
multiple versions installed at the same time you will encounter problems. The
most notable issue is trying to open two versions of one program. For example,
1
If you open both Word 2003 and Word 2007,, then restart your computer you
will find that Word will not open right away. In fact, your computer will need to
reinstall upon trying to open Word 2003 or Word 2007 taking a considerable
amount of time.
2
Click the All programs
3
Click Microsoft office Word 2007
4
a. Title bar
i. File name, format,
format application
5
ii. New, Open, Convert, Save, and so on…
Those with arrows have additional commands you can choose
6
e. The Zoom Slider
7
a. When opening Word 2007 it automatically starts with a new
document
b. To close that document, select Office Button > Close
c. Creating a new document, select Office Button > New.
d. In the top middle of the new window under Black and recent click
on Blank Document and then select the Create button in the
bottom right of the
t window.
8
e. Saving a document
i. Try to save your files when you begin to prevent the
possibility of losing your document later due to some
random computer failure
ii. To save a document, select Office Button > Save or Save As
1. This time, simply choose Save
2. Select My Documents as the location to save
a. This is the default location to save
b. This is the best choice to save all of your files as
it is easy to back up this folder
c. You can also make folders within the My
Documents folder for or better organization
3. Give the file a name, mywordfile
4. Word Document will save as a Word 2007 document
(.docx) and is not compatible with older versions
unless the compatibility package was installed on the
computer that tries to open the file
iii. Keyboard shortcut:
sh Ctrl+S
iv. To save as an older file format
1. Select Office Button > Save As > Word 97-2003
97
a. This will save as a .doc
2. In the Title bar it now shows the document is a .doc .
and you are working in the Compatibility Mode
a. This means that you will not have the newn
Word 2007 specific features
b. This also means your Word 97-2003 2003 document
is compatible with the older versions of Word
v. Close this file, create a new Word 2007 document and save
as a yourname.docx
9
10
4- Visual aids
Visual aids help you with creating and editing your documents. They help
with the layout and design in getting you precise measurements and
better ways to view
a. Rulers
i. On the Ribbon, select the View tab > in the Show/Hide
group > click Ruler
ii. The rulers
ruler show the page by inches
iii. In the top and left rulers there are Margin Markers
indicated by the division of white and blue
iv. The arrows, boxes, and L’s indicate indenting and tabs
11
b. Zoom
i. 125% default
ii. Zoom Slider
1. Bottom right corner
iii. View Tab
1. Zoom
One page, two pages, 100% and so on…
iv. Easiest way to zoom Ctrl + [your mouse scroll]
5- Orientation
6- Margins
A margin is the space between the text and the edge of the printed
paper at the top, bottom, left, and right of the page
a. Margins by default if changed will change for the entire document
12
i. To change the margin visually, simply move your mouse
pointer into the left margin on the ruler and then click and
drag to set your new margin
ii. To change the margin by using exact numbers
1. On the Ribbon, select the Page Layout tab > in the
Page Setup group > click Margins
2. Select one of the predesigned margins or select
Custom Margins and change the settings in the new
window
13
7- Formatting Text
Formatted text has control codes indicating the fonts, bold or italic type,
margins, indents, columns, tabs, headers and footers
a. Resize text
i. Select any letter, number, word, sentence, or paragraph
ii. On the Ribbon, select the Home tab > in the Font group >
click A or A
iii. On the Ribbon, select the Home tab > in the Font group >
click on the down arrow to open a menu of different sizes,
then hover over some of the sizes and watch how the text in
the document changes
14
b. Basic style changes
i. On the Ribbon, select the Home tab > in the Font group >
Hover over:
1. B for Bold
2. I for italics
3. U for Underline
c. “Highlighting” text
Highlight” selected text
i. “Highlight
1. Select any letter, number, word, sentence, or
paragraph
2. On the Ribbon, select the Home tab > in the Font
group > click Text Highlight Color (down arrow for
dropdown menu)
a. Choose Yellow
8- Navigating Documents
ocuments
Navigation is the way you move around in your document. There are many
keyboard shortcuts and options in the Scrollbar to move to different sections
of your document
16
ii. Page Up and Page Down keys move up or down one page at
a time
17
c. Using the Scrollbar feature
i. On the far right of your screen click on the up arrow to move
up and on the down arrow to move down
ii. Click and drag the slider in between the two arrow to
change what you view
iii. Click in between the arrows and the slider and you will
move up or down more quickly
18
9- Cut, Copy, Paste, and Move text
These are options for you to cut, copy, paste, or move selections of text and
other objects in you document
19
a. Cut and Paste one word
vi. Select any word
vii. On the Ribbon, select the Home tab > in the Clipboard
group > Cut
viii. Click into the new location for the word you copied
click on your mouse and from the menu choose Paste
ix. Right-click
from the menu
x. Keyboard shortcuts
1. Cut - Ctrl+X
2. Paste - Ctrl + V
20
b. Move text
xi. Select any word
xii. Click (and don’t let go) inside the selected word
xiii. Drag your mouse to the desired location and drop (let go of
the mouse button) the text
22
Change the page size.
size
Zoom in and out to view various parts of the document.
document
View multiple pages.
pages
Access Word Options to change many Word settings.
settings
To Print:
Select the pages you would like to print -- either all pages or a range of
pages.
Check the Collate box if you are printing multiple copies of a multi-page
multi
document.
23
12- Working with Text Box
24
25
13- Working with Shapes
Left-click
click your mouse and while holding it down, drag your mouse until the
shape is the desired size.
Release
ease the mouse button.
26
14- Working with Tables
Table
27
28
Control & Systems Engineering Department
St
1 Class Computer Programming
Lecturer Ass. Saba T. Salim
Learning the ins and outs of the Development Environment before you
learn visual basic is somewhat like learning for a test you must know
where all the functions belong and what their purpose is. First we will
start with labeling the development environment.
2. What Is Visual Basic?
1 - 13
Control & Systems Engineering Department
St
1 Class Computer Programming
Lecturer Ass. Saba T. Salim
involves keeping track of several different files, and accessing these files
individually within the Visual Basic environment, as needed.
4. Object-Related Concepts
Figure (1)
Controls: The icons with which the user interacts are called controls.
Commonly used controls include command buttons, option buttons,
check boxes, labels, text boxes, picture boxes and menus. The user will
typically activate a control (e.g., click on a command button) to produce
an event as shown in figure above.
Objects: Forms and controls are referred to collectively as objects. Most
objects are associated with events; hence, objects may include their own
unique event procedures. Objects are also associated with their own
properties and methods.
Properties: Objects include properties that generally define their
appearance or behavior. The choice of properties depends on the type of
object. For example, the name, caption, height, width, background color,
location and font are some of the more common properties associated
with a command button.
2 - 13
Control & Systems Engineering Department
St
1 Class Computer Programming
Lecturer Ass. Saba T. Salim
Figure (2)
If you choose to create a new project, you will see a group of windows
similar to that shown in Fig below. The Visual Basic IDE (Integrated
Design Environment) is made up of a number of components:
3 - 13
Control & Systems Engineering Department
St
1 Class Computer Programming
Lecturer Ass. Saba T. Salim
Title Bar
The top line is called the Title Bar. It includes the project name, an icons
that minimize the group of windows, change the size of the group, or
close Visual Basic on the right.
Menu Bar
The second line is called the Menu Bar. Selecting one of the choices
(File, Edit, View, Project, and Format . . . Help) causes one of Visual
Basic’s drop-down menus to appear.
Figure (3)
Toolbar
The third line is called the Standard Toolbar. The icons on this line
duplicate several of the more commonly used menu selections that are
available via the drop-down menus accessed from the Menu Bar.
4 - 13
Control & Systems Engineering Department
St
1 Class Computer Programming
Lecturer Ass. Saba T. Salim
Toolbox
The Toolbox contains icons that represent commonly used controls, such
as a label, text box, command button, picture box, check box, and so on.
You can select a control from the Toolbox and place it in the current
Form Design Window by double-clicking on the control icon (thus
placing the control in the center of the window), or by clicking once on
the control icon, then clicking on the desired location within the Form
Design Window and dragging the mouse so that the control has the
desired size.
Once a control has been placed in the Form Design Window, the
associated code (i.e., the associated Visual Basic instructions) can be
viewed or edited by double-clicking on the control.
Figure (4)
5 - 13
Control & Systems Engineering Department
St
1 Class Computer Programming
Lecturer Ass. Saba T. Salim
Text box Draws a box that can display text and let the user type
in text
Drive list box Draws a drive list box that displays all the disk drives
available
Directory list box Draws a directory list box that displays a directory on a
particular disk drive
File list box Draws a file list box that displays files in a specific
6 - 13
Control & Systems Engineering Department
St
1 Class Computer Programming
Lecturer Ass. Saba T. Salim
directory
Figure (5)
Properties Window
We have already learned that every object has properties associated with
it. Each object has its own unique list of properties. The Properties
Window allows you to assign or change the properties associated with a
particular object (i.e., a particular form or control).
7 - 13
Control & Systems Engineering Department
St
1 Class Computer Programming
Lecturer Ass. Saba T. Salim
Project Window
The Project Window displays a hierarchical list of the files associated
with a given project. These files represent individual forms and modules.
You can display a form or module within the Project Container Window
by double-clicking on the corresponding icon within the Project Window.
Also, you can select either the Object View or the Code View by clicking
on one of the two leftmost icons within the toolbar at the top of the
Project Window.
8 - 13
Control & Systems Engineering Department
St
1 Class Computer Programming
Lecturer Ass. Saba T. Salim
Figure (6)
9 - 13
Control & Systems Engineering Department
St
1 Class Computer Programming
Lecturer Ass. Saba T. Salim
To execute a Visual Basic project, simply click on the Start button in the
Toolbar (see Fig 6), or select Start from the Run menu. The execution can
be temporarily suspended by clicking on the Break button, or by selecting
Break from the Run menu. The execution of a paused project can then be
resumed by clicking on the Run button, or by selecting Continue from the
Run menu. To end the execution, simply click on the End button, or select
End from the Run menu.
10 - 13
Control & Systems Engineering Department
St
1 Class Computer Programming
Lecturer Ass. Saba T. Salim
Each form and control has properties assigned to it by default when you
start up a new project. There are two ways to display the properties of an
object. The first way is to click on the object (form or control) in the form
window. Then, click on the Properties Window or the Properties Window
button in the tool bar. The second way is to first click on the Properties
Window. Then, select the object from the Object box in the Properties
Window. Shown is the Properties Window for the stopwatch application:
Figure (8)
11 - 13
Control & Systems Engineering Department
St
1 Class Computer Programming
Lecturer Ass. Saba T. Salim
A very important property for each object is its name. The name is used
by Visual Basic to refer to a particular object in code.
Object names can be up to 40 characters long, must start with a letter,
must contain only letters, numbers, and the underscore (_) character.
Names are used in setting properties at run time and also in establishing
procedure names for object events.
Now, Set properties of the form, three buttons, and six labels:
Form1:
Border Style:1-Fixed Single
Caption: Stopwatch Application
Command1:
Caption: &Start Timing
Name: cmdStart
Command2:
Caption: &End Timing
Name: cmdEnd
Command3:
Caption: E&xit
Name: cmdExit
Label1:
Caption: Start Time
Label2:
Caption: End Time
Label3:
Caption: Elapsed Time
Label4:
Border Style 1-Fixed Single
Caption: [Blank]
Name: lblStart
Label5:
Border Style: 1-Fixed Single
Caption: [Blank]
Name: lblEnd
Label6:
Border Style: 1-Fixed Single
Caption: [Blank]
Name: lblElapsed
12 - 13
Control & Systems Engineering Department
St
1 Class Computer Programming
Lecturer Ass. Saba T. Salim
Figure (10)
The third part of this example will be continued in the next lecture
13 - 13
Control & Systems Engineering Department
1St Class Computer Programming
Lecturer Asst. Saba T. Salim
Before we complete the third step of the example solution, we will try
to clarify three important things these are: 1): some of the properties that
related the controls that used in the example as an attempt to learn the
benefits of these properties and 2): Code Editor Window and finally:
variables used by visual basic to hold information.
Property Description
Name The name of the object so you can call it at runtime
This specifies the command button's background color. Click
the BackColor's palette down arrow to see a list of common
BackColor
Windows control colors, you must change this to the style
property from 0 - standard to 1 - graphical
Determines whether the command button gets a Click event if
Cancel
the user presses escape
Caption Holds the text that appears on the command button.
Determines whether the command button is active. Often,
Enable you'll change the enable property at runtime with code to
prevent the user pressing the button
Produces a Font dialog box in which you can set the caption's
Font
font name, style and size.
Height Positions the height of the object - can be used for down
Left Positions the left control - can be used for right
Mouse If selected to an icon can change the picture of the mouse
Pointer pointer over that object
Hold's the name of an icon graphic image so that it appears as a
Picture picture instead of a Button for this option to work the graphical
tag must be set to 1
This determines if the Command Button appears as a standard
Style
windows dialog box or a graphical image
Tab index Specifies the order of the command button in tab order
Whether the object can be tabbed to ( this can be used in labels
Tab Stop
which have no other function )
2
Control & Systems Engineering Department
1St Class Computer Programming
Lecturer Asst. Saba T. Salim
If the mouse is held over the object a brief description can be
Tool Tip
displayed (for example hold your mouse over one of the above
Text
pictures to see this happening
If you want the user to see the button/label select true otherwise
Visible
just press false
Width Show the width of the object
Most of These properties can be set or changed either manually from the
object properties window or using the programming code, we must note here
that the property (Name) is changed using the project properties window
only. And if you try to change it using the programming code then the
following error message will appear:
Figure (1)
And using several properties your form may looks like the following:
Figure (2)
3
Control & Systems Engineering Department
1St Class Computer Programming
Lecturer Asst. Saba T. Salim
If you select Code View within the Project Window, or if you double-click
on a control icon within the Form Design Window, the Code Editor Window
will open, displaying the Visual Basic code associated with the currently
active form. Fig. 1.4 shows the Code Editor Window of our form shown in
figure (2).
Event selected by
the programmer
Provided
automatically
Figure (3)
Ignore the individual Visual Basic instructions for now. Notice, however, the
two list boxes at the top of the window. The leftmost list box showing the
Object List box; it allows you to select the event procedures associated with
a particular object (e.g., a particular command button, form, label, text box,
etc.). The rightmost list box is called the Procedure List box; for the current
4
Control & Systems Engineering Department
1St Class Computer Programming
Lecturer Asst. Saba T. Salim
object, it allows you to select the event procedure associated with a
particular type of event (e.g., Click, DragDrop, KeyDown, MouseDown,
etc.). To define the event procedure associated with a command button,
double-click on the button. This will cause the Code Editor Window to be
displayed, as shown in Fig. 3 Within this window, the first and last line of
each event procedure (e.g., Private Sub Command1_Click) and (End Sub)
are provided automatically, separated by a blank line. The actual Visual
Basic commands must be inserted between these two lines.
You can also set or modify properties while your application is running. To
do this, you must write some code. The code format is:
FormName.ObjectName.Property = NewValue
BackColor property of a form name command1, we'd type:
Command1.BackColor = vbblue
the expression (vbred) is a function provided by visual basic programming
language allows you to add preferred color beyond the function (vb) or you
can use the function (QBcolor) followed by a color number as in the table
shown later:
Command1.BackColor = QBColor(01)
The names you assign to objects are used by Visual Basic to set up a
framework of event-driven procedures for you to add code to. The format for
each of these subroutines (all object procedures in Visual Basic are
subroutines) is:
Sub ObjectName_Event (Optional Arguments)
.
.
End Sub
Visual Basic provides the Sub line with its arguments (if any) and the End
Sub statement. You provide any needed code.
5
Control & Systems Engineering Department
1St Class Computer Programming
Lecturer Asst. Saba T. Salim
Yellow 6 Bright White 15
White 7
Grey 8
Also we can change the "Caption" property using the programming code as
follows:
Command1.caption="close"
Or you may change the command button activity using Enable property
through the programming code as follows:
Command1.enabled=false (true)
The properties of changing dimensions or Caption font formatting can be
changed also through the programming code as follows:
Command1.width=No.
Command1.Hight=No.
Command1.Left=No.
Command1.Top=No.
Command1.FontSize=No.
Command1.FontItalic = True(False)
Command1.fontBold=True(False)
Command1. FontUnderline=True(False)
Command1.Font="Times New Roman"
Figure (4)
6
Control & Systems Engineering Department
1St Class Computer Programming
Lecturer Asst. Saba T. Salim
Long 4 byte & Boolean 2 byte None
Single 4 byte ! Currency 8 byte @
Double 8 byte # String 2 byte $
Date 8 byte None Variant 16 byte None
There are two principle ways to add variables to your applications:
The first method – called implicit declaration – is to let Visual Basic
automatically create the variable for you. Implicit declaration means that
Visual Basic automatically creates a variant for each identifier it recognizes
as a variable in an application.
To implicitly type a variable, use the corresponding suffix shown above in
the data type table. For example,
Amount% = 300
TextValue$ = "This is a string"
Code: VB
Dim VariableName As DataType
Static VariableName As DataType
Private VariableName As DataType
Public VariableName As DataType
In each case, the name of the variable and its data type are provided as part
of the declaration.
Dealing with the variables requires knowledge of two main concepts related
to the variables that are
1) Life time of the variable: the period that the variable keeps its value.
2) Scope (visibility): the program ability to reach and use the variable.
Before allocating storage space for a variable, decide what the variable's
lifetime will be, or in other words, which procedures and which modules
should have access to the variable's value.
Þ Procedure level
Þ Procedure level, static
7
Control & Systems Engineering Department
1St Class Computer Programming
Lecturer Asst. Saba T. Salim
Þ Form and module level
Þ Global level
The life time of this type is started as we declare the variable using the above
statements within an event to the end of that event. And the visibility will be
thorough that event only.
9 To make a procedure level variable retain its value upon exiting the
procedure; replace the Dim keyword with Static:
The life time of this type of variables is maintained to the end of the program
i.e the variable will keep it value every time the event that hold the variable
is occurred while the visibility will be thorough that event only.
9 Form (module) level variables retain their value and are available to
all Procedures within that form (module). Form (module) level variables are
declared in the declarations part of the general object in the form's
(module's) code window. The Dim or Private keyword is used:
9 Global level variables retain their value and are available to all
procedures within an application. Module level variables are declared in the
declarations part of the general object of a module's code window. Use the
Global or Public keyword:
8
Control & Systems Engineering Department
1St Class Computer Programming
Lecturer Asst. Saba T. Salim
It would certainly be easier to make every variable Global. You wouldn't
have to think twice about it's availability at any given time. But sometimes,
every byte of memory counts, so don't give your variables any more life than
they actually require.
Figure (5)
Procedure Routine1 has access to X, Y, and A (loses value upon
termination) Procedure Routine2 has access to X, Y, and B (retains value)
Procedure Routine3 has access to X, Z, and C (loses value).
Now, we can get back to step three of our design example (attaching code):
All that’s left to do is attach code to the application. We write code for every
event a response is needed for. In this application, there are three such
events: clicking on each of the command buttons.
1. Double-click anywhere on the form to open the code window. Or, select
‘View Code’ from the project window.
2. Click the down arrow in the Object box and select the object named
(general). The Procedure box will show (declarations). Here, you declare
three form level variables:
9
Control & Systems Engineering Department
1St Class Computer Programming
Lecturer Asst. Saba T. Salim
Option Explicit
Dim StartTime As Variant
Dim EndTime As Variant
Dim ElapsedTime As Variant
The Option Explicit statement forces us to declare all variables. The other
lines establish StartTime, EndTime, and ElapsedTime as variables global
within the form.
The overall code is shown below:
Option Explicit
Dim starttime As Variant
Dim endtime As Variant
Dim elapsedtime As Variant
10
Control & Systems Engineering Department
1St Class Computer Programming
Lecturer Asst. Saba T. Salim
Figure (6)
11
Control & Systems Engineering Department
1St Class Computer Programming
Lecturer Asst. Saba T. Salim
12