chapter = date: feb 18, 2011 time: 11:49am - buch.de · accounting–data processing. 3. ......

15

Upload: vocong

Post on 03-Aug-2018

214 views

Category:

Documents


0 download

TRANSCRIPT

Chapter = Date: Feb 18, 2011 Time: 11:49 am

Chapter = Date: Feb 24, 2011 Time: 12:45 pm

Mastering IDEAScript

Chapter = Date: Feb 24, 2011 Time: 12:45 pm

Chapter = Date: Feb 24, 2011 Time: 12:45 pm

Mastering IDEAScript

The Definitive Guide

JOHN PAUL MUELLER

John Wiley & Sons, Inc.

Chapter = Date: Feb 24, 2011 Time: 12:45 pm

Copyright © 2011 by CaseWare IDEA Inc. All rights reserved.

Published by John Wiley & Sons, Inc., Hoboken, New Jersey.Published simultaneously in Canada.

No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any formor by any means, electronic, mechanical, photocopying, recording, scanning, or otherwise, except aspermitted under Section 107 or 108 of the 1976 United States Copyright Act, without either the priorwritten permission of the Publisher, or authorization through payment of the appropriate per-copy feeto the Copyright Clearance Center, Inc., 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax(978) 646-8600, or on the Web at www.copyright.com. Requests to the Publisher for permission shouldbe addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ07030, (201) 748-6011, fax (201) 748-6008, or online at http://www.wiley.com/go/permissions.

Limit of Liability/Disclaimer of Warranty: While the publisher and author have used their best efforts inpreparing this book, they make no representations or warranties with respect to the accuracy orcompleteness of the contents of this book and specifically disclaim any implied warranties ofmerchantability or fitness for a particular purpose. No warranty may be created or extended by salesrepresentatives or written sales materials. The advice and strategies contained herein may not besuitable for your situation. You should consult with a professional where appropriate. Neither thepublisher nor author shall be liable for any loss of profit or any other commercial damages, includingbut not limited to special, incidental, consequential, or other damages.

IDEA® is a registered trademark of CaseWare International Inc.

For general information on our other products and services or for technical support, please contact ourCustomer Care Department within the United States at (800) 762-2974, outside the United States at(317) 572-3993, or fax (317) 572-4002.

Wiley also publishes its books in a variety of electronic formats. Some content that appears in printmay not be available in electronic books. For more information about Wiley products, visit our Website at www.wiley.com.

Library of Congress Cataloging-in-Publication Data:

Mueller, John, 1958-Mastering IDEAScript: the definitive guide/John Paul Mueller.

p. cm.Includes index.

ISBN 978-1-118-00448-7 (pbk.); 978-1-118-01783-8 (ebk); 978-1-118-01784-5 (ebk);978-1-118-01785-2 (ebk)

1. Auditing–Data processing. 2. Accounting–Data processing. 3. Scripting languages(Computer science) 4. Data structures (Computer science) I. Title.

HF5667.12.M37 2011657.0285′53–dc22

2010045246

Printed in the United States of America.10 9 8 7 6 5 4 3 2 1

Chapter = Date: Feb 24, 2011 Time: 12:47 pm

Contents

Preface xi

Acknowledgments xvii

CHAPTER 1 Introducing IDEAScript 1

Understanding Automation 1

Understanding How You Use Macros 3

Having Things Your Way 6

Considering Your Skills 7

Summary 8

CHAPTER 2 Creating Your First IDEAScript Application 9

Understanding the Macro Types 9

Opening the Visual Script Editor 11

Writing a Hello World Application 15

Building Your Application 19

Summary 20

CHAPTER 3 Understanding the Basics of the IDEAScript Editor 21

Working with Windows 21

Hiding and Viewing Windows 27

Working with Menus and Toolbars 29

Summary 37

CHAPTER 4 Designing Structured Applications 39

Understanding the Parts of an Application 40

Understanding the Methods Used to Create an Application 41

Using the Macro Recorder 45

Working with Subroutines and Functions 52

v

Chapter = Date: Feb 24, 2011 Time: 12:47 pm

vi Contents

Making Your Code Easy to Read 56

Adding Your Application to a Toolbar or Menu 57

Summary 60

CHAPTER 5 Working with Data 63

Understanding Variables and Constants 63

Choosing a Data Type 67

Employing Operators 82

Formatting Data 85

Creating Custom Data Types 89

Summary 91

CHAPTER 6 Using Conditional Statements and Loops 93

Making Decisions Using the If . . . Then . . . Else Statement 93

Choosing between Options Using Select Case 95

Performing Tasks a Specific Number of Times with For . . . Next 99

Performing Tasks Using Conditions with Do Loop 102

Adding Error Trapping to Your Application 106

Redirecting Macro Flow Using GoTo 112

Summary 112

CHAPTER 7 Understanding IDEA Databases 115

Considering the Parts of a Database 115

Introducing the IDEA Database System 118

Opening a Database for Use 119

Checking the Database History 120

Obtaining Field Statistics 122

Setting Database Criteria 125

Indexing a Database 125

Sorting a Database 127

Modifying Database Comments 129

Committing the Database 131

Closing a Database 133

Summary 133

CHAPTER 8 Working with Databases 135

Adding One Database to Another Using Append Database 135

Comparing Two Databases Using CompareDB 138

Chapter = Date: Feb 24, 2011 Time: 12:47 pm

Contents vii

Working with Keys 140

Exporting a Database Using ExportDatabase 145

Working with Fields Using Field 150

Working with Records 152

Working with Tables 157

Summary 164

CHAPTER 9 Considering the CaseWare IDEA Object Model 165

Considering the IDEA Object Model 165

Working with the Task Object Model 170

Summary 193

CHAPTER 10 Performing Mathematical Tasks 195

Performing Basic Math 195

Using Advanced Math 198

Employing Analysis 200

Summary 205

CHAPTER 11 Interacting with Arrays 207

Understanding How Arrays Work 207

Creating and Using Arrays 208

Copying Data between Arrays 212

Summary 213

CHAPTER 12 Creating Interactive Dialog Boxes 215

Creating Great Dialog Boxes 216

Using the Basic Controls 218

Obtaining the Visual Appearance You Want 232

Interacting with Dialog Boxes Using Code 235

Adding Pictures to Your Dialog Boxes 244

Summary 247

CHAPTER 13 Locating Information in Databases 249

Performing Searches Efficiently 249

Using the Built-in Search Features 251

Creating a Custom Search 268

Summary 269

Chapter = Date: Feb 24, 2011 Time: 12:47 pm

viii Contents

CHAPTER 14 Importing and Exporting Data 271

Considering the Import and Export Features 271

Performing Data Extractions 283

Managing PDF Data 290

Managing Text Data 294

Managing Excel Data 306

Managing Access Data 310

Summary 315

CHAPTER 15 Working with Files 317

Considering the File Format 317

Using the File IO Features 318

Using External Variables 346

Summary 348

CHAPTER 16 Working with Other Applications 349

Considering IDEAScript and Visual Basic for Applications (VBA)Differences 349

Understanding the Word and Excel Object Models 350

Running Word from IDEA 351

Running IDEA from Excel 355

Summary 359

CHAPTER 17 Performing Data Analysis Tasks 361

Performing Stratification 361

Performing Summarization 367

Creating a Pivot Table 371

Employing Random Record Sampling Using RandomSample 374

Performing Gap Detection 376

Checking Distribution Using SystematicSample 378

Merging Databases 380

Summary 389

CHAPTER 18 Working with Charts and Graphs 391

Choosing the Correct Chart or Graph 391

Creating a Basic Graph 393

Chapter = Date: Feb 24, 2011 Time: 12:47 pm

Contents ix

Defining Analytical Charts 399

Summary 405

CHAPTER 19 Defining Reports 407

Defining a Report 407

Outputting Data in PDF Format 412

Outputting Data in Word Format 414

Summary 418

CHAPTER 20 Considering Database Security 419

Considering Programmatic Data Security 419

Choosing the Correct Data Type 421

Validating Data 421

Protecting Dialog Boxes 427

Summary 428

CHAPTER 21 Debugging Your Application 429

Understanding the Kinds of Application Errors 429

Running and Stopping the Application 433

Using Breakpoints 434

Stepping through the Application 435

Using the Watch Window 438

Relying on Message Boxes 444

Summary 445

CHAPTER 22 Performing Project Management Tasks 447

Creating a Plan for Your Application 448

Keeping Track of Application Files 449

Working within a Group 450

Documenting Your Application 451

Summary 453

CHAPTER 23 Converting Visual Script to IDEAScript 455

Considering the Benefits of Using IDEAScript 455

Performing the Conversion 456

Making Changes and Saving the Result 458

Summary 461

Chapter = Date: Feb 24, 2011 Time: 12:47 pm

x Contents

About the Author 463

About the Website 465

Index 467

Chapter = Date: Feb 18, 2011 Time: 11:49 am

Preface

Most people want to perform tasks faster because, let’s face it, time is precious andyou’d much rather spend your time doing something other than sitting at your desk

waiting for the computer to complete a task. That’s where IDEAScript comes into play.By using IDEAScript, you can automate tasks. You can tell the computer to accomplishtasks and let you know when the work is finished. Mastering IDEAScript: The DefinitiveGuide is your window to IDEAScript. It helps you understand how IDEAScript worksand how you can use it to do amazing things with IDEA, all without having to sit at yourdesk to observe the computer doing it. If that sounds interesting, read on!

About This Book

Mastering IDEAScript: The Definitive Guide is designed to help the complete novicedevelop the skills required to write simple applications using IDEAScript. The overallgoal of this book is to make it possible for you to automate all of those tasks that youused to perform manually. Of course, you still have to start the task and interpret theresults—even the best automation can’t do that for you.

Automation is one of those terms that’s used a lot, but is never quite explained byanyone. For the purposes of this book, automation means that you’ll be able to write anapplication that follows a procedure you create—the same procedure you use every dayto perform tasks. It’s just that simple. Instead of you spending time filling in forms andanswering questions, you give all the required information to the computer as part ofyour application and let it do the work. The result is that you become more productiveand spend less time sitting in that chair bored stiff.

The techniques in this book go further, though. Let’s say that you have an assistantand want the assistant to help with some of the work. You can write an application thatasks the assistant very simple questions and then automates the rest of the task for theassistant so you don’t have to help as much. The result is that your assistant also becomesmore capable and efficient. By using forms and other techniques described in this book,you make it possible for less-skilled helpers to perform a task using the same approachyou do, making the result look the same as if you had done it.

IDEAScript provides a wealth of capabilities and Mastering IDEAScript: The DefinitiveGuide tells you all about them. For example, you might want to remotely control anexternal application without having to work too hard to do it. Using IDEAScript, you

xi

Chapter = Date: Feb 18, 2011 Time: 11:49 am

xii Preface

create the code required to perform the manipulation one time, and then let the computerperform the task for you from then on.

Finally, this book tells you about a few unique tasks you can perform usingIDEAScript. Do you have an external file that doesn’t quite want to import using the nor-mal techniques provided by IDEA? Well, you can define an application using IDEAScriptthat makes it possible to import just about anything into IDEA. This book tells you howto accomplish this kind of task.

How This Book Is Organized

This book discusses IDEAScript starting from simple topics and moving on toward morecomplex topics. The initial topics also focus on tasks that you perform more often. As youprogress through the book, you start to discover tasks that are less used, but extremelyuseful in many situations. In fact, this book may present you with some new ways ofaccomplishing tasks that you hadn’t considered when using the GUI. Here’s a list of thechapters in this book:

■ Chapter 1: Introducing IDEAScript: This chapter helps you understand whatautomation can help you do. It presents you with the concepts behind using macrosand helps you set reasonable goals for working with IDEAScript.

■ Chapter 2: Creating Your First IDEAScript Application: This chapter beginsby helping you understand the two kinds of macros you can create with IDEA:IDEAScript and Visual Script. It then presents you with the editors used to create eachmacro type. This is also the first chapter where you write an application—somethingvery basic that you can use as a starting point for other applications in the book.

■ Chapter 3: Understanding the Basics of the IDEAScript Editor: This chapterprovides you with the details of using the IDEAScript Editor.

■ Chapter 4: Designing Structured Applications: This chapter helps you under-stand the basic parts of an application. You discover how to write code quickly andefficiently by copying it from the help file or from IDEA’s history. In addition, youlearn how to use the Macro Recorder to create complete applications without writingany code at all. Finally, this chapter shows you how to add your application to anIDEA toolbar or menu so that you can access it quickly.

■ Chapter 5: Working with Data: This chapter helps you understand what variablesand constants are (essentially they’re a sort of storage container) and how to use themwithin your application. This chapter introduces data types, a method of categorizingdata stored in variables and constants. Finally, you discover some basic techniquesfor working with variables and constants.

■ Chapter 6: Using Conditional Statements and Loops: This chapter begins build-ing on the basic structures you learned about in Chapter 4. In this case, you learnhow to perform tasks conditionally using any criteria you want and how to performtasks multiple times (either a specific number of times or until the application meetscertain specifications). This chapter also helps you understand what to do abouterrors that occur in your application.

Chapter = Date: Feb 18, 2011 Time: 11:49 am

Preface xiii

■ Chapter 7: Understanding IDEA Databases: This chapter introduces databasesfrom an IDEAScript perspective. You discover how databases are put together andlearn how to open databases for processing. After the introductory material, thischapter provides you with the information you need to perform basic tasks, such asindexing, sorting, and closing your database.

■ Chapter 8: Working with Databases: This chapter takes the next step after basicdatabase management. You discover how to perform some intermediate level tasks,such as comparing databases and exporting them. Finally, this chapter shows youhow to work with fields, records, and tables in a database.

■ Chapter 9: Considering the CaseWare IDEA Object Model: This chapter intro-duces you to the concept of objects, which are a representation of something in yourapplication. Think of objects as they appear in the real world and you have the basicidea. Once you have the basics of objects down, this chapter introduces you to anumber of IDEAScript objects, especially those used to perform tasks.

■ Chapter 10: Performing Mathematical Tasks: This chapter helps you understandhow to perform math tasks using IDEAScript. You’ll also see details on using a coupleof the analysis-related tasks provided by IDEA.

■ Chapter 11: Interacting with Arrays: This chapter demonstrates how to use arrays,which provide a method of storing like or associated values together for easy access.

■ Chapter 12: Creating Interactive Dialog Boxes: This chapter presents techniquesfor working with complex dialog boxes. IDEAScript lets you create dialog boxes ofany complexity so that you can ask the user questions, have the user fill out forms,or interact with the user in other ways. As part of this chapter, you learn how to usethe various graphical elements used to create dialog boxes.

■ Chapter 13: Locating Information in Databases: This chapter helps you learnhow to find information within databases. These search techniques can make itquite easy to find any data within the database, even if you aren’t quite sure whatyou’re trying to find. IDEA makes it quite easy to perform complex searches withouta lot of work on your part—IDEAScript makes things even easier by automatingsome tasks associated with common searches.

■ Chapter 14: Importing and Exporting Data: This chapter shows you how you canobtain data from other applications and send IDEA data to other applications. Theability to import and export data is essential in today’s world of connected computers.You want to have a number of solutions available to make data accessible for furtheranalysis or for sharing with other people.

■ Chapter 15: Working with Files: This chapter describes how to work with externalfiles of all types. You can use external files to store other information or import datafrom external files that IDEA might not support directly. In addition, you can useexternal files to hold configuration information or even use them to log applicationerrors. In short, external files are really important when creating moderately complexIDEAScript applications.

■ Chapter 16: Working with Other Applications: This chapter describes how tomake other applications work with IDEA in a number of ways. In this chapter,you discover specifically how to use IDEA with both Microsoft Word and MicrosoftExcel, but the techniques shown will work with other applications, too. Once you