Beginning Visual Basic 6
Authors: Peter Wright
Venue:  (1998)

From the Book:Who's This Book For? This book is designed to teach you how to write useful programs in Visual Basic 6 as quickly and as easily as possible. There are two kinds of beginners for whom this is the ideal book: You're a beginner to programming and you've chosen Visual Basic as the place to start. Great choice! Visual Basic is easy, it's fun and it's also powerful. This book will hold your hand throughout. You can program in another language but you're a beginner to Windows programming. Again, great choice! Come in from the cold world of C or whatever language you use and enjoy This book will teach you how Visual Basic 6 does things in terms you'll understand. Along the way, I'll give you all the background information you need on Windows programming to help you to develop really professional applications. What's Covered in This Book? This book is about the Learning Edition or Standard Edition of Visual Basic. Newcomers with the Professional and Enterprise editions can also learn a great deal, but an explanation of the features specific to these two great packages is a little beyond the scope of this book. Visual Basic 6 is big and powerful. We're not going to try and look into its every nook and cranny. What we are going to do is cut a wide path through the undergrowth to a suitable clearing where we can write our own programs. Think of this book as a tour guide to Visual Basic 6 country You're only here for a short period, and it's never long enough (just like a real vacation). What you don't want is to go down every street in town. What you do want is the big picture,together with enough local understanding to enable you to find your own way around without getting into tricky situations. Sure, we'll look at some of the local highlights together, but these can only ever be a taster. So what's in the tour? There are some things you have to know, like how Visual Basic programs fit together and what the main components are. All these fundamental building blocks are covered in detail. We then take a look at what you can actually do with Visual Basic. just because something appears in Visual Basic doesn't mean it's in the book - we've only included those things that have a practical purpose. This book gets you where you want to go. At the end of the book, I have arranged for three real-world Visual Basic programs to be presented to you by professional VB programmers. These programmers have cut down their projects to fit in this book and be a little easier to follow than they might be in their natural setting. However, I think these applications will offer you a great insight into putting together everything you will have learned about Visual Basic, and using the Visual Basic language in the real world for the programs that you will want to write in the future. What Isn't Covered in This Book What I haven't put in this book is a lot of formal definitions and exhaustive lists of options. Visual Basic is a rich language, and each command has a welter of options. I'm just going to tell you what you need to know at the time. There are lots of good references, like the Visual Basic Manuals and Help Screens, that can give you all the minute detail. Visual Basic 6 Professional and Enterprise versions bring plenty of new Internet facilities to your programming environment. I haven't covered these features in this book for two very solid reasons. First, I want to include everyone with the Learning Edition of Visual Basic. Second, I don't believe it's appropriate in this book to cover the complexities of the Internet and the World Wide Web. Those topics are best dealt with in a separate book on VB6, which you'll find from Wrox Press to help you learn out about that interesting area. For this book, we cover all that is essential to core Visual Basic programming. I'm also not going to tell you how to actually use Windows. Throughout the course of the book, I assume you already know the basics of using a Windows program, such as how to select a menu option, or how to double-click something, and so on. What You Need to Use This Book Apart from a willingness to learn, you'll need access to a PC running Windows 95 and the Learning Edition of Visual Basic 6. All the source code for the examples in this book is shown in the chapters. You do not need any extra files to create the programs we discuss. However, if you do want to avoid the finger ache that comes with a lot of typing, you can download the examples from the Wrox web site: http://www.wrox.com This is a great site to check out anyway - it's full of interesting information about programming, and all the books from Wrox Press. Conventions I've used a number of different styles of text and layout in the book to help differentiate between the different kinds of information. Here are examples of the styles I use and an explanation of what they mean: Try It Outs - How Do They Work? Each step has a number. Follow the steps through. Then read How It Works to find out what's going on. Advice, hints, or background information comes in boxes like this. Important Words are in a bold type font. Words that appear on the screen in menus like the File or Window menu are in a similar font to what you see on screen. Keys that you press on the keyboard, like Ctrl and Enter, are in italics. Visual Basic code has two fonts. If it's a word that we're talking about in the text, for example, when discussing the For ... Next loop, it's in a bold font. If it's a block of code that you can type in as a program and run, then it's also in a gray box: Private Sub cmdQuitClick() End End Sub Sometimes you'll see code in a mixture of styles, like this: Private Sub cmdQuit_Click() End End Sub There are two reasons why this might be so. In both cases we want you to consider the code with the gray background. The code with a white background is either code we've already looked at and that we don't wish to examine further, or when you're typing code in, this is code that Visual Basic automatically generates and doesn't need typing in. When a line of code has been split on to two lines because of space considerations, the continuation is marked with a (bendy arrow). When typing the code in Visual Basic, you should put any lines marked like this at the end of the code on the line above. Note that VB5 does have its own line continuation character. It's a space followed by an underscore (_). I don't think this is very clear in print, so we've stuck with the bendy arrow. These formats are designed to make sure that you know what it is you're looking at. I hope they make life easier. How to Get the Most Out of This Book This book is written as a hands-on tutorial. That means you have to get your hands on the keyboard as often as possible. Throughout the book there are Try It Outs! which is where you'll find step-by-step instructions for creating and running a Visual Basic program. This program illustrates the concept that's currently being explained. I also use the Try It Outs! to teach you new concepts when it's better to see them in action first, rather than bury them in text. After each Try It Out! there is a How It Works section that explains what's going on. As the programs get longer, later in the book, some of the How It Works sections themselves get quite large. Please read them through, though. It's all part of the plan. There are a lot of what technical writers call forward references in this book. These are where I say 'Don't worry about this difficult concept here. I'll explain it in Chapter whatever'. This kind of reckless behavior will preclude me from ever entering the Logical Writers Hall Of Fame, but frankly I don't care. What I do really care about is that you have exciting and interesting programs to play with as early as possible in the book, and to do that, I sometimes have to ask to you to take things on trust. Where I do use language elements that we haven't covered properly yet, I'll tell you. And believe me, they are all there later on, as promised. At the end of each chapter is a list of my suggestions for ways to put the concepts you've just learned into practice. I've found that the best way to learn is to tinker about on your own, extending current projects and creating new ones. These suggestions are just that - suggestions so use them if you want. Appendix B contains a list of proposed solutions for the exercises. For this fourth edition of the book, I've really gone to town and asked three professional Visual Basic programmers to show us some of their programs from real projects they've been working on. They've presented us with a cut down version of their work, so we can really see what happens when Visual Basic becomes a tool to use in your everyday programming. Learning Visual Basic is one thing - but seeing it at work is quite another, so please exercise your VB muscles by following through what my professional friends have been up to! When you've finished the book, the one thing you can be sure of is that you'll be hungry for more. You'll have an excellent grounding in Visual Basic, but that's only the beginning. The whole world of Visual Basic development will be at your feet. To help you decide what to do next, I've put some unashamedly personal and opinionated advice into Appendix A - Where Do We Go From Here? This includes references for further reading should you want to learn more!