SPECIAL OFFERS
Keep up with new releases and promotions. Sign up to hear from us.
Register your product to gain access to bonus material or receive a coupon.
This book deals with Visual Basic, a programming language which is increasingly gaining ground in the face of its competitors. Addison-Wesley Nitty Gritty Visual Basic 6 offers introductions to VB, looking at the fundamentals of this language. For the more advanced programmer, this book enhances skills such as program development techniques, error handling and debugging and database access using ADO.
Preface 11
P.1 The book's conception 13
P.2 Typographic conventions 16
P.3 Where you can find help and further information 17
Part I - Start up!
Getting started with Visual Basic 21
1 Visual Basic, VBA and VBScript 23
1.1 What are Visual Basic, VBA and VBScript? 23
1.2 Programming in Visual Basic 24
1.3 What can Visual Basic do? 25
1.4 The editions of Visual Basic 27
1.5 Service Pack 4 and other updates 27
2 Introduction to VB 29
2.1 Object orientation in VB 29
2.1.1 What is an object? 29
2.1.2 What is a class? 33
2.2 Starting Visual Basic: the different project types 33
2.3 The development environment 35
2.3.1 Overview of the windows 35
2.3.2 Fundamentals of writing program code 38
2.4 The Visual Basic project 42
2.5 Important options 45
2.5.1 Options of the development environment 45
2.5.2 Compiling options 47
2.6 A first Visual Basic application 48
Part II - Take that!
Programming in Visual Basic 55
3 Fundamentals of the VBA language 57
3.1 Modules 57
3.2 Statements, expressions and operators 59
3.3 Declaring variables 67
3.3.1 Implicit declaration 67
3.3.2 Explicit declaration 67
3.4 The data types 72
3.4.1 The VBA data types 73
3.4.2 The Reddik naming convention 78
3.4.3 Static arrays 83
3.4.4 Dynamic arrays 84
3.4.5 Initializing arrays 86
3.4.6 Allocation of arrays 86
3.4.7 Structures 86
3.4.8 Symbolic constants 87
3.4.9 Enumerations (Enums) 88
3.5 Loops and branches 90
3.5.1 Conditional branches 90
3.5.2 "Branch" functions 93
3.5.3 Unconditional branches 94
3.5.4 Loops 94
3.5.5 Exiting a program block 98
3.5.6 The With statement 99
3.6 Procedures and functions 99
3.6.1 Declaring procedures and functions 100
3.6.2 Call by Value and Call by Reference 102
3.6.3 Functions that return objects 103
3.6.4 Functions that return arrays 104
3.6.5 The passing of arrays 104
3.6.6 Parameter arrays 105
3.6.7 Optional arguments 106
3.6.8 Recursion 107
3.7 Conditional compilation 108
3.8 Working with objects 109
3.8.1 Class libraries 112
3.8.2 Collections 113
3.8.3 Your own collections using dictionary objects 114
4 VBA functions and VB objects 121
4.1 The object browser 121
4.2 File and folder functions 123
4.3 String functions 127
4.3.1 Extracting partial strings and shortening strings 127
4.3.2 Compare strings and search for partial strings 127
4.3.3 Replacing strings 131
4.3.4 Conversion and creation of strings 132
4.3.5 Separating and joining strings 133
4.3.6 The left-over Len function 134
4.4 Formatting functions 135
4.5 Date functions 138
4.6 Arithmetic functions 141
4.7 Conversion functions 141
4.8 Information functions 143
4.9 Interaction functions 144
4.10 Functions for output and input 146
4.10.1 The MsgBox function 146
4.10.2 The InputBox function 149
4.11 The VB objects 149
5 Controls and forms 153
5.1 Standard controls, ActiveX and windowless controls 153
5.2 Common elements of all controls 155
5.2.1 The most important com
This is my first foreword, which tells you that this is also my first book. I myself have never read a foreword before. Now that I have written one I can see the reason for it: I want to give you an overview of this book and show you what possibilities are open to you when it comes to the Internet.
This book deals only with Visual Basic, my favorite programming language which is increasingly gaining ground in the face of its competitors. This begs the question perhaps as to why Visual Basic has become such a popular programming language in the meantime.
With Visual Basic you can do everything conceivable for Microsoft operating systems. Visual Basic supports the latest Microsoft technologies so that your programs are always up to date. You can usually download state-of-the-art technologies directly from the Microsoft website, install and (with a little know-how) insert them into Visual Basic.
With Visual Basic you can produce not only normal Windows applications but also (with some limitations) do object-oriented programming, access almost any databases and other data sources, develop reusable components and controls, create real multilayer applications, write multithreading components and create multimedia and Internet applications. So just about everything is possible!
OK, so some features are missing in the current Version 6, for example real inheritance, but firstly you will probably get by best with those features available for standard applications and secondly the new Version 7 adds clear finishing touches.
Visual Basic is not all about advantages and I do not wish to keep silent about the disadvantages. One of the most serious of these is that Microsoft with Visual Basic still carries around a lot of padding (you could say garbage), which was inherited from the original version of (Microsoft-DOS)Basic. Another disadvantage is that programming of the new features for the current VB versions was very 'sloppy' and favors the user with a lot of inconsistencies and bugs. Unfortunately Microsoft to date has set a lot of store by the development of new features and has hardly, if at all removed the bugs in the old ones. VB.NET adds the finishing touches here. Microsoft has committed each developer in the VB team to develop no more new features but firstly to remove errors in the current ones if they receive reports of more than 25 (it begs the question of how development was done previously).
But I do not wish to join in the chorus of other people in making out that Visual Basic is bad. If you know the pitfalls, VB is a wonderful, fast and simple programming language. I have got used to simply ignoring the defective or bad programmed features I know and, where necessary, using other components (bought or as Freeware mostly from the Internet). You will certainly read some criticisms in this book, but you will find rather more that most features are described positively (I have simply not bothered to describe features which are not going to be used). So that you avoid the pitfalls, I do of course describe the problems as well and usually provide a solution.
And to those programmers who believe C program to be considerably faster, suffice it to say that the VB compiler utilizes the Microsoft C compiler at the lowest level.
As you may have already noticed, this book is a paperback. Therefore space available is terribly limited compared with a "proper" book. The Nitty Gritty series as its name suggests gets down to the nitty-gritty so everything has to be scaled down. I am working on the basis therefore that you understand the basics of programming and have a sound knowledge of Windows. On this assumption you can learn with the help of this book the most important features and components of Visual Basic. Since Visual Basic in the meantime has become a very powerful programming language, I cannot describe everything in approximately 400 pages. The book does not deal with some of the features and components which are in my view less important (unfortunately including OOP).
The individual sections of the book are usually laid out so that a description telling you how to use a particular feature in practice follows a general introduction. Then there is an overview in table format showing you the most important elements. The conclusion is frequently a section in which I describe tips and tricks for that particular topic.
So that you get an overall view of the topics included in the book, I am listing them here, chapter by chapter:
Chapter 1 gives you an overview of Visual Basic and VBA, the programming language used in Visual Basic.
Chapter 2 introduces you to programming with Visual Basic (without however explaining the fundamentals of programming) and gives an overview of the possibilities open to you.
Chapter 3 describes in great detail how you program with VBA (variables, loops, branches, functions, etc.).
Chapter 4 explains the functions of the VBA library and describes the few objects predefined in VB.
In Chapter 5 there is a description of the correct procedure for dealing with standard controls, the most important ActiveX controls and windowless controls using forms and menus. Because of the large number and complexity of some ActiveX controls, not all ActiveX elements are described in this chapter.
Chapter 6 explains, in my view, the most important program development technologies, with some topics, such as graphics and printing, and database programming only being described in later chapters.
Chapter 7 concentrates on the treatment of run-time errors, debugging and
testing an application.
Chapter 8 deals with the output of text and graphics on forms or the printer using VB graphics methods and, by way of example, the Windows GDI functions.
Chapter 9 explains how to deal with FileSystemObjects to access the file system and to read and write text files.
Chapter 10 introduces you to working with databases. This chapter emphasizes the fundamentals of data access with ActiveX Data Objects and leaves untouched many "Quick and Dirty" Visual Basic database features.
Finally, Chapter 11 shows you how to create an installation version out of your VB project that can be installed on other computers.
Of course you should also know what topics are not described in the book. For this reason I am listing them here.
Object-oriented programming, i.e. the production of intrinsic classes and based on this the production of a listing of classes, class hierarchies, COM (component object model) components and ActiveX controls, is omitted from this book. At first I had planned to include some fundamental information, but this had to be removed again because of lack of space. In addition this information would probably have been too incomplete.
Internet programming is omitted from this book. Visual Basic alone is also insufficient to write good Internet applications. I am in the process of writing a book especially about Internet programming with ASP and Visual Basic in the Nitty Gritty series. Along with buying this book I recommend "Microsoft Active Server Pages" by Jörg Krause.
I hope I have made the overview of this book easier for you.