visual basic 6 - special edition 1998

877 353 0
visual basic 6 - special edition 1998

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

i Contents P2/V4/SWG2 SEU VB6 7.23.98 Marcia FM LP#1 Using Visual Basic ® 6 Using Special Edition Untitled-1 9/1/98, 10:18 AM1 P2/V4/SWG2 SEU VB6 7.23.98 Marcia FM LP#1 ii Special Edition Using Visual Basic 6 Untitled-1 9/1/98, 10:19 AM2 iii Contents P2/V4/SWG2 SEU VB6 7.23.98 Marcia FM LP#1 Brian Siler and Jeff Spotts Visual Basic ® 6 Using Special Edition Using Untitled-1 9/1/98, 10:19 AM3 P2/V4/SWG2 SEU VB6 7.23.98 Marcia FM LP#1 iv Special Edition Using Visual Basic 6 Special Edition Using Visual Basic ® 6 Copyright© 1998 by Que All rights reserved. No part of this book shall be reproduced, stored in a retrieval system, or transmitted by any means, electronic, me- chanical, photocopying, recording, or otherwise, without written permission from the publisher. No patent liability is assumed with respect to the use of the information contained herein. Although every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omis- sions. Neither is any liability assumed for damages resulting from the use of the information contained herein. International Standard Book Number: 0-7897-1542-2 Library of Congress Catalog Card Number: 98-84617 Printed in the United States of America First Printing: September 1998 00 99 98 4 3 2 1 Trademarks All terms mentioned in this book that are known to be trademarks or service marks have been appropriately capitalized. Que cannot attest to the accuracy of this information. Use of a term in this book should not be regarded as affecting the validity of any trademark or service mark. Windows is a registered trademark of Microsoft Corporation. Visual Basic is a registered trademark of Microsoft Corporation. Warning and Disclaimer Every effort has been made to make this book as complete and as accurate as possible, but no warranty or fitness is implied. The information provided is on an “as is” basis. The authors and the publisher shall have neither liability or responsibility to any person or entity with respect to any loss or damages arising from the infor- mation contained in this book. Untitled-1 9/1/98, 10:19 AM4 v Contents P2/V4/SWG2 SEU VB6 7.23.98 Marcia FM LP#1 Contents at a Glance I Getting Started with Visual Basic 1 Starting Out with Visual Basic 11 2 Creating Your First Program 17 3 Visual Basic Building Blocks 39 4 Using Visual Basic’s Default Controls 59 II Programming with Visual Basic 5 Responding to the User with Event Procedures 95 6 Giving More Control to the User: Menus and Toolbars 107 7 Using Dialog Boxes to Get Information 139 8 Using Variables to Store Information 159 9 Visual Basic Programming Fundamentals 173 10 Controlling the Flow of Your Program Code 203 11 Managing Your Project: Sub Procedures, Functions, and Multiple Forms 223 III Visual Basic Program Components 12 Microsoft Common Controls 245 13 Working with Control Arrays 289 14 Creating ActiveX Controls 305 15 Extending ActiveX Controls 341 16 Classes: Resusable Components 359 IV Visual Basic Interfaces 17 Multiple Document Interface Applications 381 18 Proper Interface Design 409 19 Using Visual Design Elements 425 V Advanced Programming Topics 20 Accessing the Windows API 449 21 Working with Files 469 22 Using OLE to Control Other Applications 489 23 Master’s Toolbox 501 Untitled-1 9/1/98, 10:19 AM5 P2/V4/SWG2 SEU VB6 7.23.98 Marcia FM LP#1 vi Special Edition Using Visual Basic 6 VI Visual Basic and Databases 24 Database Basics 527 25 The Data Control and Data-Bound Controls 545 26 Using Data Access Objects (DAO) 565 27 Using Remote Data Objects (RDO) 595 28 Using ActiveX Data Objects (ADO) 611 29 Creating Reports 641 VII Visual Basic and the Internet 30 Using VBScript 665 31 Active Server Pages 687 32 ActiveX Documents 719 33 Visual Basic and Other Uses of the Internet 741 VIII Appendixes A Introduction to the Development Environment 759 B Packaging Your Applications 775 C SQL Summary 793 Index 829 Untitled-1 9/1/98, 10:19 AM6 vii Contents P2/V4/SWG2 SEU VB6 7.23.98 Marcia FM LP#1 Table of Contents Introduction 1 Fundamental Visual Basic Program- ming 2 Working with Visual Basic Components 3 Creating Application Interfaces 4 Advanced Visual Basic Programming 4 Database Programming Techniques 5 Additional References 5 Source Code and Programs Used in This Book 6 Conventions and Special Elements Used in This Book 6 I Getting Started with Visual Basic 9 1 Starting Out with Visual Basic 11 What Is a Computer Program? 12 Computer Programs and Programming Languages 13 Visual Basic Is a Smart Language 14 The Importance of Designing Your Program 14 How Design Fits into the Programming Process 15 Program Design in a Nutshell 15 From Here… 16 2 Creating Your First Program 17 Creating Your Program’s User Inter- face 18 Getting Started 18 Saving Your Work 20 Getting Information From the User 23 Adding a TextBox Control 23 Labeling Your Program’s Controls 28 Adding a Command Button 29 Changing a Form’s Properties 30 Saving Your Work—Again… 31 Coding Your Program’s Actions 31 Responding to Events 31 Specifying Event Procedures 33 Writing Program Code 34 Running Your Program 36 From Here… 38 3 Visual Basic Building Blocks 39 Forms 40 Parts of a Form 40 What Do Forms Do? 41 Using Controls 41 What Are Controls? 41 Control Functions 42 Exploring Properties 42 Property Basics 43 Common Properties 44 Using Properties to Control an Object’s Size 44 Using Properties to Adjust an Object’s Position 44 Changing Properties at Runtime 45 Using Properties to Control User Inter- action 48 Referencing Forms and Controls from Your Code 49 A First Look at Methods and Events 50 Taking Action with Methods 50 Responding to Actions with Events 51 How Properties and Methods Are Re- lated 51 Form Properties Revisited 52 Displaying a Form 55 From Here… 57 Untitled-1 9/1/98, 10:19 AM7 P2/V4/SWG2 SEU VB6 7.23.98 Marcia FM LP#1 viii Special Edition Using Visual Basic 6 4 Using Visual Basic’s Default Controls 59 Introduction to the Intrinsic Controls 60 Working with Text 62 Displaying Text with a Label Con- trol 63 Entering Text with a Text Box 65 Controls for Making Choices 66 The Command Button 67 Check Boxes 68 Option Buttons 68 The List Box 70 The Combo Box 75 Special-Purpose Controls 78 Scrollbars 78 The Timer Control 81 Frames 83 Working with Multiple Controls at Designtime 85 Selecting Multiple Controls 86 Using the Properties Window 87 Using the Form Editor Toolbar 87 Using the Format Menu 89 Multiple Controls in a Frame 90 Working with the Controls Collection 90 Changing All Controls 90 Changing Selected Controls 91 From Here… 91 II Programming with Visual Basic 93 5 Responding to the User with Event Procedures 95 Introducing Events 96 Handling Events in Your Programs 97 Determining When an Event Has Oc- curred 97 Types of Events 98 Writing Event Procedures 100 Calling an Event Procedure from Code 101 Understanding Event Sequences 102 Multiple Events for Each Action 102 Determining the Order of Events 103 From Here… 106 6 Giving More Control to the User: Menus and Toolbars 107 Creating a Menu Bar 108 Common Menus 109 Setting Up the Main Items 110 Multiple-Level Menus 112 Grouping Menu Items 114 Modifying the Menu 115 Adding Access Keys and Shortcut Keys for Quick Access 116 Writing Code for the Menu Items 119 Optional Settings 119 Creating Pop-Up Menus 122 Creating the Menu to Be Dis- played 123 Activating a Pop-Up Menu 124 Using Toolbars in Visual Basic 124 Toolbar Basics 125 Getting the Images for Your Toolbar 126 Creating a Standard Toolbar 127 Creating the Toolbar’s Buttons 129 Starting a Toolbar Example 131 Enabling the Buttons with Code 132 Creating a Toolbar with Code 133 Allowing the User to Customize the Toolbar 135 Using the CoolBar Control 136 From Here… 137 7 Using Dialog Boxes to Get Information 139 Keeping the User Informed 140 Understanding the Message Box 140 Displaying a Message 141 Untitled-1 9/1/98, 10:19 AM8 ix Contents P2/V4/SWG2 SEU VB6 7.23.98 Marcia FM LP#1 Returning a Value from the MsgBox Function 143 Demonstrating the MsgBox Func- tion 146 Getting Information from the User 146 Setting Up the InputBox Function 146 Values Returned by InputBox 147 Using Built-In Dialog Boxes 148 General Usage of the CommonDialog Control 148 Testing the CommonDialog Con- trol 149 The File Dialog Boxes 150 The Font Dialog Box 152 The Color Dialog Box 154 The Print Dialog Box 155 The Help Dialog Box 157 Creating Your Own Dialog Boxes 157 Creating a Custom Dialog Box 157 Using Form Templates for Other Dialog Boxes 157 From Here… 158 8 Using Variables and Constants to Store Information 159 Introduction to Variables 160 Naming Variables 160 Types of Variables 161 Variable Declarations 163 Explicit Declaration 163 Implicit Declaration 164 Fixed-Length Strings 165 Variable Arrays 166 Determining Where a Variable Can Be Used 166 Creating Variables That Are Available Everywhere 167 Keeping a Variable Local 168 Using Static Variables 168 Using the Option Explicit Statement 169 What’s Different About Constants 171 How to Use Constants 171 Constants That Visual Basic Sup- plies 171 Creating Your Own Constants 172 From Here… 172 9 Visual Basic Programming Fundamentals 173 Writing Statements 174 Using Assignment Statements 175 Using Math Operations 176 Addition and Subtraction 177 Multiplication and Division 178 Exponentiation 181 Operator Precedence 181 Working with Strings 182 String Concatenation 183 Determining the Length of the String 185 Changing the Case of a String 185 Searching a String 187 Extracting Pieces of a String 189 Getting Rid of Spaces 191 Replacing Characters in a String 191 Working with Specific Characters 193 Strings and Numbers 194 Formatting Results 195 Specific Formatting Functions 195 Using the Format Function 197 Manipulating Date Values 200 From Here… 202 10 Controlling the Flow of Your Program Code 203 Making Decisions in Your Program 204 Using the If Statement 204 Working with the False Condition 205 Working with Multiple If State- ments 206 Using Select Case 207 Untitled-1 9/1/98, 10:19 AM9 P2/V4/SWG2 SEU VB6 7.23.98 Marcia FM LP#1 x Special Edition Using Visual Basic 6 Working with Loops 209 For Loops 210 Do Loops 211 Enumeration Loops 214 Debugging Your Programs 214 Stepping Through Your Code 216 Working in the Immediate Win- dow 217 Tracking Variable Values 218 Error Trapping 219 Using the On Error Statement 219 Labeling Code Lines 219 Controlling Program Flow After an Error 220 Determining the Type of Error 221 From Here… 222 11 Managing Your Project: Sub Procedures, Functions, and Multiple Forms 223 Using Procedures and Functions 224 Working with Procedures 224 Working with Functions 231 Determining the Scope of Procedures and Functions 232 Reusing Functions and Proce- dures 233 Working with Multiple Forms 235 Adding New Forms to Your Pro- gram 235 Adding Code Modules to a Project 236 Accessing the Forms and Modules of a Project 236 Managing Components in Your Project 237 Managing Program References 238 Controlling Your Controls 238 Adding Forms, Modules, and Classes to the Project 238 Removing Pieces 241 Controlling How Your Program Starts 241 Setting the Startup Form 241 Using Sub Main 241 From Here… 242 III Visual Basic Program Components 243 12 Microsoft Common Controls 245 Introduction to the Common Controls 246 The ImageList: A Fundamental Common Control 248 Setting Up an ImageList at Designtime 248 Setting Up an ImageList with Code 249 Organizing Your Data 250 Using the ListView Control 251 Using the TreeView Control 258 Using the TabStrip Control 261 Accepting User Input 266 Using an ImageCombo Control 266 The UpDown Control 269 Working with Dates 271 Sliding into Numbers 275 Reporting Status and Progress 278 Adding a Status Bar to Your Pro- gram 279 Progress Bar 284 Adding Video with the Animation Con- trol 285 From Here… 287 13 Working with Control Arrays 289 Introducing Control Arrays 290 Control Array Elements 290 Understanding the Advantages of Con- trol Arrays 290 Creating a Control Array 291 Adding Control Arrays to a Form 291 Writing Code for a Control Array 294 Removing Elements from a Control Ar- ray 296 Working with Control Arrays 296 Using a Control Array in Your Pro- grams 296 Untitled-1 9/1/98, 10:19 AM10 [...]... Report 65 4 Customizing Your Report 65 7 Using the Crystal Reports Control 65 8 From Here… 66 1 VII Visual Basic and the Internet 66 3 30 Using VBScript 66 5 Introduction to VBScript 66 6 Enhancing the Internet with VBScript 66 6 VBScript on the Web Server 66 7 VBScript in the Browser 66 8 Tools Used with VBScript 67 1 The VB Scripting Engine 67 1 Host Application 67 1 Text Editor 67 2 Advanced Web Tools 67 2 The... the DataGrid 62 1 Splitting Up the Grid 62 3 Customizing the Grid’s Layout 62 4 Customizing the Grid with Code 62 6 Using ActiveX Data Objects 62 7 Making the Connection with ADO Working with Recordsets 63 0 The Command Object 63 6 Disconnected Recordsets 63 7 Creating a Disconnected Recordset 63 7 9/1/98, 10:19 AM P2/V4/SWG2 SEU VB6 7.23.98 Marcia FM LP#1 62 7 xvi Special Edition Using Visual Basic 6 Reconnecting... Untitled-2 7 9/1/98, 10:20 AM P2/V4/SWG2 SEU VB6 154 2-2 7.23.98 Marcia INTRO LP#1 8 Untitled-2 Introduction 8 9/1/98, 10:20 AM P2/V4/SWG2 SEU VB6 154 2-2 7.23.98 Marcia INTRO LP#1 P A R T Getting Started with Visual Basic 1 2 Creating Your First Program 17 3 Visual Basic Building Blocks 39 4 Untitled-3 Starting Out with Visual Basic 11 Using Visual Basic s Default Controls 9 P2/V4/SWG2 SEU VB6 154 2-2 Marcia... RDC 60 8 From Here… 60 9 28 Using ActiveX Data Objects (ADO) 61 1 Introducing ADO 61 2 Data Connection Methods 61 2 Installation 61 2 Setting Up a Data Source 61 3 Using the ADO Data Control 61 4 Setting Up the ADO Data Control 61 5 Connecting the ADO Data Control to a Data Source 61 6 Displaying Data 61 8 Changing the Record Source from Code 61 9 Using the DataGrid Control 61 9 Getting Data into the Grid 62 0 Setting... The VBScript Language 67 3 Working with Variants Only 67 3 Using Objects for Added Power 67 4 Accessing the File System 67 5 Using VBScript in Internet Explorer 67 6 Events and Procedures 67 7 Forms 67 9 Using ActiveX Controls 68 1 The Windows Scripting Host 68 2 Running Scripts 68 3 Useful Objects and Methods 68 4 From Here… 31 Active Server Pages 16 687 Introduction to Active Server Pages 68 8 Active Server Pages... Recordset 63 8 Uses of a Disconnected Recordset 63 9 From Here… 64 0 29 Creating Reports 64 1 Creating a Simple Report 64 2 Setting Up the Data Source 64 2 Adding a Data Report to Your Project 64 3 Setting Up the Data Report 64 4 Displaying the Report 64 7 Enhancing Your Data Reports 64 8 Predefined Report Fields 64 8 Adding Graphics 64 9 Printing and Exporting 65 1 Function Fields 65 2 Using Crystal Reports 65 3 Creating... What is Visual Basic? s Is Visual Basic a program? s What can you do with Visual Basic? s Why should I learn Visual Basic? Microsoft’s Visual Basic product is defined as a programming system Simply put this programming system is used to write Windows-based computer programs; it includes the Visual Basic language as well as a number of tools that help you write these programs You don’t use Visual Basic. .. system in Visual Basic Brian is a graduate of the University of Memphis with a B.S in Computer Science He has developed applications using Visual Basic, C, HTML, and SQL on a variety of platforms including PCs, AS/400, UNIX, and Vax He was the co-author of Que’s Special Edition Using Visual Basic 5, Second Edition, and Que’s Platinum Edition Using Visual Basic 5 Brian may be contacted via e-mail at... Part I of the book, “Getting Started with Visual Basic, ” you are introduced to what Visual Basic can do and how to work in the development environment Untitled-2 2 9/1/98, 10:20 AM P2/V4/SWG2 SEU VB6 154 2-2 7.23.98 Marcia INTRO LP#1 Working with Visual Basic Components 3 Chapter 1, “Starting Out with Visual Basic, ” discusses how Visual Basic works to create Windows-based computer programs and starts you... Marcia FM LP#1 xii Special Edition Using Visual Basic 6 Connecting the Property Page to the Control 353 Using Your Property Page 354 Handling Multiple Control Selections 355 Control Error Handling 355 From Here… 357 16 Classes: Reusable Components 359 Understanding Classes 360 Object-Oriented Programming 360 Classes in Visual Basic 361 Building Class Modules 361 Starting a New Class Module 362 Adding Properties . the Internet 66 3 30 Using VBScript 66 5 Introduction to VBScript 66 6 Enhancing the Internet with VBScript 66 6 VBScript on the Web Server 66 7 VBScript in the Browser 66 8 Tools Used with VBScript 67 1 The. VB6 7.23.98 Marcia FM LP#1 Using Visual Basic ® 6 Using Special Edition Untitled-1 9/1/98, 10:18 AM1 P2/V4/SWG2 SEU VB6 7.23.98 Marcia FM LP#1 ii Special Edition Using Visual Basic 6 Untitled-1. Key Features 760 Starting Up 761 The Visual Basic Work Area 762 Using the Menu Bar 763 Accessing Functions with the Toolbars 764 Organizing Visual Basic s Controls 766 The Canvas of Your Programs 769 Controlling

Ngày đăng: 17/04/2014, 09:18

Tài liệu cùng người dùng

Tài liệu liên quan