practical approach to programming in visual basic
DESCRIPTION
Overview of Practical Approach to Programming in Visual Basic by O. Omorogiuwa and M. S. OkundamiyaTRANSCRIPT
COVER PAGE
ii Practical Approach to Programming in Visual Basic
First Published 2010
Published in Nigeria by:
STEMIC PUBLICATIONS
P. O. Box 10612,
Benin City,
Nigeria.
E-mail: [email protected]
Copyright © O. Omorogiuwa and M. S. Okundamiya
All Right Reserved
No part of this publication may be reproduced, stored in any retrievable
system, or transmitted in any form or by any means: electronic, mechanical,
photographic (photocopying), recording or otherwise without the prior
written permission of the publisher.
ISBN: 978-978-907-303-0
Printed by:
Eguavoen Printers
53 Wire Road, Opp Emotan College Gate,
Benin City.
Tel: +23480358112619
iiiM. S. Okundamiya
PREFACE
Practical Approach to Programming in Visual Basic is intended to be of use
to both novices seeking to learn Visual Basic, and to those proficient in other
languages that plan to cross-train from other programming languages. Visual
Basic language provides a uniquely powerful, yet easy to learn programming
environment allowing even the absolute beginner to rapidly create and
deploy Windows applications.
Practical Approach to Programming in Visual Basic is divided into seven
chapters. It begins with the essential concepts of computer programming
aimed at equipping the reader with the required knowledge and techniques
for effective and practical computer programming without necessarily having
a pre-knowledge on computer programming. Chapter two introduces the
basic concepts of VB 6.0: with practical steps on how a beginner can create
his (or her) first VB application, modify and add control properties, and how
such applications can be improved. Chapter three through six detailed on
Visual Basic language covering topics such as Visual Basic data and variable
types: single and multi-dimensional arrays, along with their declaration
statement; control properties: string handling, file I/O, date and time
manipulation; operators and flow control, and functions. Finally it ends with
data storage, database creation and access using customized VB programs.
The CD gives the exact demonstration of the VB designs taught in the
textbook and more. Throughout this book, liberal use is made of code
excerpts providing practical examples of theory in action, which practically
guides both seasoned and inexperienced programmers. It is intended that
iv Practical Approach to Programming in Visual Basic
having read this book, the programmer will confidently be able to developing
Windows applications using Visual Basic.
We sincerely appreciate God Almighty for His infinite mercy, wisdom, love
and protection over our families. Thanks to our dearly beloved brethren,
Franklin Ibegbulem and Hillaree John, for painstakingly going through this
work despite their tight schedule.
O. Omorogiuwa
M. S. OkundamiyaApril, 2010.
vM. S. Okundamiya
CONTENTS
Preface iii
Contents v
Chapter One: Concept of Computer Programming.
1.1 Introduction 1
1.2 Program Developmental Cycle 1
1.2.1 Analyzing the Program 2
1.2.2 Developing a Solution 2
1.2.3 Coding the Solution 4
1.2.4 Testing and Debugging the Program 5
1.3 Qualities of a Good Program 5
1.4 Classification of Programming Languages 6
1.4.1 Low Level Language (LLL) 6
1.4.2 High Level Language (HLL) 7
1.4.3 Very High Level Language (VHLL) 7
1.4.4 Procedural Languages 7
1.4.5 Non - Procedural Languages 8
1.5 Translators 8
1.5.1 Assembler 8
vi Practical Approach to Programming in Visual Basic
1.5.2 Interpreter 8
1.5.3 Compiler 8
1.6 Elements of a Programming Language 9
1.6.1 Data and Variables 9
1.6.2 Statements and Operators 11
1.6.3 Program Flow Control 13
1.6.4 Array 18
1.6.5 Functions 18
1.6.6 Structures 18
Chapter Two: Overview of Visual Basic 6.0 Programming Language.
2.1 Introduction 19
2.2 Defining Basic Terms 21
2.2.1 Object 21
2.2.2 Form 21
2.2.3 Screen 21
2.2.4 Clipboard 22
2.2.5 Application 22
2.2.6 Object-Oriented Programming
22
2.2.7 Event-Driven Programming 22
2.2.8 Procedure-Oriented Programming 23
viiM. S. Okundamiya
2.3 Creating the Graphical User Interface (GUI) 23
2.3.1 Guiding Principles 24
2.3.2 Interface Style 25
2.4 Writing the Code 26
2.5 Creating Your First Application 28
2.5.1 Starting Visual Basic 6.0 29
2.5.2 Adding Controls to the Form 32
2.5.3 Improving Your Application 43
Chapter Three: Data, Variables and Constants in Visual Basic.
3.1 Introduction 45
3.2 Visual Basic Data Types 45
3.2.1 Numeric Data Types 45
3.2.2 Non-Numeric Data Types 46
3.2.3 Suffixes for Literals 47
3.3 Variables 48
3.3.1 Naming Conventions 49
3.3.2 Declaring Variables 49
3.3.3 Scope of Variables 51
3.3.4 Assigning Values to Variables 57
3.4 Constants 57
3.5 Arrays in VB 58
3.5.1 Dimension of an Array 58
3.5.2 Declaring Arrays 59
3.5.3 Working with Arrays 60
Chapter Four: Control Properties in Visual Basic.
4.1 Introduction 65
viii Practical Approach to Programming in Visual Basic
4.2 Handling of Common Controls 66
4.2.1 Label 66
4.2.2 Text Box 68
4.2.3 Command Button 68
4.2.4 Picture Box 73
4.2.5 Frame 73
4.2.6 Image Box 74
4.2.7 List Box 74
4.2.8 Combo Box 75
4.2.9 Check Box 78
4.2.10 Option Button 78
4.2.11 Drive List Box 79
4.2.12 Directory List Box 80
4.2.13 File List Box 80
4.3 Graphics 81
4.3.1 Adding or Removing Pictures 82
4.3.2 Drawing Controls 83
4.4 Multimedia 83
Chapter Five: Operators and Flow Control in Visual Basic.
5.1 Arithmetic Operators 85
5.2 Conditional (Relational) Operators 88
5.3 Logical Operators 88
5.4 Using the If . . . Then . . . Else Statement with Operators 89
ixM. S. Okundamiya
5.5 Using Select Case…End Select Control
Structure with Operators 95
5.6 Looping 100
5.6.1 Do Loop 101
5.6.2 For . . . Next Loop 104
Chapter Six: Functions in Visual Basic.
6.1 Introduction 107
6.2 VB Built-In Functions 107
6.2.1 Message Box ( ) Function 107
6.2.2 The Input Box ( ) Function 113
6.3 Mathematical Functions 115
6.4 Formatting Functions 119
6.4.1 Tab Function 119
6.4.2 Space Function 120
6.4.3 Format Function 121
6.5 String Manipulation Functions 123
6.6 Dates and Times 127
Chapter Seven: Data Storage in Visual Basic.
7.1 Introduction 130
7.2 Data Files 130
7.2.1 Types of Files 131
7.2.2 Opening and Closing Files 132
7.3 Working with a Sequential File 139
7.4 Working with a Random File 151
References 157
x Practical Approach to Programming in Visual Basic
Index 158