COVER PAGE

FIRST EDITION

in

O. OMOROGIUWA M. S. OKUNDAMIYA

ii First Published 2010

Practical Approach to Programming in Visual Basic

Published in Nigeria by: STEMIC PUBLICATIONS P. O. Box 10612, Benin City, Nigeria. E-mail: st_mico@yahoo.com

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

M. S. Okundamiya

iii

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. Okundamiya April, 2010.

M. S. Okundamiya

v

CONTENTS Preface Contents Chapter One: Concept of Computer Programming. 1.1 1.2 Introduction Program Developmental Cycle 1 1 2 2 4 5 5 6 6 7 7 7 8 8 8 iii v

1.2.1 Analyzing the Program 1.2.2 Developing a Solution 1.2.3 Coding the Solution 1.2.4 Testing and Debugging the Program 1.3 1.4 Qualities of a Good Program Classification of Programming Languages

1.4.1 Low Level Language (LLL) 1.4.2 High Level Language (HLL) 1.4.3 Very High Level Language (VHLL) 1.4.4 Procedural Languages 1.4.5 Non - Procedural Languages 1.5 Translators

1.5.1 Assembler

vi 1.5.2 Interpreter 1.5.3 Compiler 1.6

Practical Approach to Programming in Visual Basic

8 8 9 9 11 13 18 18 18

Elements of a Programming Language

1.6.1 Data and Variables 1.6.2 Statements and Operators 1.6.3 Program Flow Control 1.6.4 Array 1.6.5 Functions 1.6.6 Structures

Chapter Two: Overview of Visual Basic 6.0 Programming Language. 2.1 2.2 Introduction Defining Basic Terms 19 21 21 21 21 22 22

2.2.1 Object 2.2.2 Form 2.2.3 Screen 2.2.4 Clipboard 2.2.5 Application 2.2.6 22 2.2.7 Event-Driven Programming Object-Oriented Programming

22 23

2.2.8 Procedure-Oriented Programming

M. S. Okundamiya

vii 23 24 25 26 28 29 32 43

2.3

Creating the Graphical User Interface (GUI)

2.3.1 Guiding Principles 2.3.2 Interface Style 2.4 2.5 Writing the Code Creating Your First Application

2.5.1 Starting Visual Basic 6.0 2.5.2 Adding Controls to the Form 2.5.3 Improving Your Application Chapter Three: Data, Variables and Constants in Visual Basic. 3.1 3.2 Introduction Visual Basic Data Types

45 45 45 46 47 48 49 49 51 57 57 58 58 59 60

3.2.1 Numeric Data Types 3.2.2 Non-Numeric Data Types 3.2.3 Suffixes for Literals 3.3 Variables 3.3.1 Naming Conventions 3.3.2 Declaring Variables 3.3.3 Scope of Variables 3.3.4 Assigning Values to Variables 3.4 3.5 Constants Arrays in VB

3.5.1 Dimension of an Array 3.5.2 Declaring Arrays 3.5.3 Working with Arrays Chapter Four: Control Properties in Visual Basic. 4.1 Introduction

65

viii 4.2

Practical Approach to Programming in Visual Basic

Handling of Common Controls

66 66 68 68 73 73 74 74 75 78 78 79 80 80 81 82 83 83

4.2.1 Label 4.2.2 Text Box 4.2.3 Command Button 4.2.4 Picture Box 4.2.5 Frame 4.2.6 Image Box 4.2.7 List Box 4.2.8 Combo Box 4.2.9 Check Box 4.2.10 Option Button 4.2.11 Drive List Box 4.2.12 Directory List Box 4.2.13 File List Box 4.3 Graphics

4.3.1 Adding or Removing Pictures 4.3.2 Drawing Controls 4.4 Multimedia

Chapter Five: Operators and Flow Control in Visual Basic. 5.1 5.2 5.3 5.4 Arithmetic Operators Conditional (Relational) Operators Logical Operators Using the If . . . Then . . . Else Statement with Operators 85 88 88 89

M. S. Okundamiya

ix

5.5 5.6

Using Select Case…End Select Control Structure with Operators Looping 95 100 101 104

5.6.1 Do Loop 5.6.2 For . . . Next Loop Chapter Six: Functions in Visual Basic. 6.1 6.2 Introduction VB Built-In Functions

107 107 107 113 115 119 119 120 121 123 127

6.2.1 Message Box ( ) Function 6.2.2 The Input Box ( ) Function 6.3 6.4 Mathematical Functions Formatting Functions

6.4.1 Tab Function 6.4.2 Space Function 6.4.3 Format Function 6.5 6.6 String Manipulation Functions Dates and Times Data Storage in Visual Basic.

Chapter Seven: 7.1 7.2 Introduction Data Files

130 130 131 132 139 151 157

7.2.1 Types of Files 7.2.2 Opening and Closing Files 7.3 7.4 Working with a Sequential File Working with a Random File

References

x Index

Practical Approach to Programming in Visual Basic

158

Sign up to vote on this title
UsefulNot useful