The Waite Group's Microsoft QuickBASIC Bible [1 ed.] 1556152620

Covers: QuickBASIC up to vers. 4.5, GW-BASIC, BASICA, PowerBASIC We wrote this book with a special approach in mind. Th

507 170 24MB

English Pages XVIII; 940 [965] Year 1990

Report DMCA / Copyright

DOWNLOAD PDF FILE

Table of contents :
KEYWORDS, STATEMENTS,AND FUNCTIONS
Title Page
Table of Contents
Foreword
Preface
Acknowledgments
Introduction: A Task-Oriented Overview of QuickBASIC
SECTION I - CORE
Chapter 1 Variables and Types
Chapter 2 Flow Control
Chapter 3 Decisions and Operators
Chapter 4 Procedures
Chapter 5 Strings
Chapter 6 Arrays and Data
Chapter 7 Math
Chapter 8 Simple I/O
Chapter 9 Trapping and Errors
Chapter 10 Time (Timing, Date, and Time)
SECTION II - MULTIMEDIA
Chapter 11 Graphics
Chapter 12 Sound
Chapter 13 Light Pen and Joystick
SECTION III - DEVICES
Chapter 14 Keyboard
Chapter 15 Printer
Chapter 16 Communications Port
Chapter 17 Files
SECTION IV - DEVELOPMENT
Chapter 18 DOS and Program Management
Chapter 19 Port and Memory
Chapter 20 Mixed Language
Chapter 21 Metacommands
Chapter 22 Debugging
SECTION V APPENDIXES
Appendix A Microsoft KnowledgeBase
Appendix B CompuServe Files
Appendix C Third-Party Routines
Appendix D QuickBASIC for the Macintosh
Appendix E Statements Specific to OS/2 in Microsoft BASIC Compiler Versions 6.0 and 7.0
Appendix F Error Messages & Error Codes
Appendix G Control Codes
Appendix H ASCII Characters
Index
KEYWORDS, STATEMENTS, AND FUNCTIONS BY CATEGORY
Recommend Papers

The Waite Group's Microsoft QuickBASIC Bible [1 ed.]
 1556152620

  • 0 0 0
  • Like this paper and download? You can publish your own PDF file online for free in a few minutes! Sign Up
File loading please wait...
Citation preview

KEYWORDS, STATEMENTS, AND FUNCTIONS $DYNAMIC 782 $INCLUDE 783 $STATIC 785 ABS 274 Add Watch 802 AND 124 ASC 210 ATN 275 BEEP 477 BLOAD 700 Break On Errors 804 BSAVE 703 CALL (BASIC procedures) 159 CALL (Non-BASIC procedures) 742 CALL ABSOLUTE 747 CALL INT860LD, CALL INT86XOLD 751 CALL INTERRUPT, CALL INTERRUPTX 755 CDBL 277 CHAIN 161 CHDIR 661 CHR$ 211 CINT 278 CIRCLE 402 CLEAR 662 Clear All Breakpoints 805 CLNG 280 CLOSE 570 CLS 305 : (Colon) 665 COLOR 407 COM ON/OFF/STOP 548 COMMAND$ 667 COMMON 165 + (Concatenation) 126 CONST 63 COS 282 CSNG 283

CSRLlN 307 CVD 571 CVDMBF 574 CVI 575 CVL 576 CVS 577 CVSMBF 578 DATA 248 DATE$ (Function and statement) 380 DECLARE (BASIC procedures) 173 DECLARE (Non-BASIC procedures) 760 DEF FN 176 DEF SEG 765 DEFtype 67 Delete All Watch 806 Delete Watch 806 DIM 250 DO... LOOP 95 DOUBLE 70 DRAW 413 END 669 ENVIRON 670 ENVIRON$ 673 EOF 579 EQV 128 ERASE 255 ERDEV 355 ERDEV$ 358 ERL 359 ERR 360 ERROR 362 EXIT 97 EXP 284 FIELD 581 FILEATIR 583 FILES 585 FIX 286

FOR ... NEXT 100 FRE 706 FREEFILE 588 FUNCTION 179 GET (File I/O) 589 GET (Graphics) 419 GOSUB ... RETURN 183 GOTO 105 HEX$ 72 History On 808 IF 130 IMP 135 INKEY$ 309 INP 709 INPUT 313 INPUT # 592 INPUT$ (File I/O) 595 INPUT$ (Keyboard) 317 Instant Watch 809 INSTR 214 INT 287 INTEGER 73 10CTL 674 10CTL$ 676 KEY 517 KEYln) ON/OFF/STOP 519 KILL 677 LBOUND 257 LCASE$ 216 LEFT$ 217 LEN 219 LET 74 LINE 422 LINE INPUT 320 LINE INPUT # 597 LOC 601 LOCATE 322 LOCK 603 LOF 605 LOG 288

LONG 76 LPOS 531 LPRINT 534 LPRINT USING 537 LSET 606 LTRIM$ 610 MID$ (Function) 221 MID$ (Statement) 223 MKD$ 611 MKDIR 679 MKDMBF$ 613 MKI$ 614 MKL$ 615 MKS$ 616 MKSMBF$ 617 MOD 137 NAME 618 NOT 138 OCT$ 77 ON COM GOSUB 550 ON ERROR GOTO 365 ON KEY(n) GOSUB 523 ON PEN GOSUB 496 ON PLAY GOSUB 478 ON STRIG GOSUB 497 ON TIMER GOSUB 382 ON UEVENT GOSUB 368 ON GOSUB 108 ON GOTO 110 OPEN 620 OPEN COM 552 OPTION BASE 258 OR 140 OUT 711 PAINT 426 PALETTE, PALETTE USING 431 PCOPY 435

PLAY ON/OFF/STOP 484 PMAP 438 POINT 442 POKE 718 POS 325 PRESET, PSET 444 PRINT 327 PRINT # 626 PRINT USING 330 PRINT # USING 632 PUT (File I/O) 632 PUT (Graphics) 447 RANDOMIZE 290 READ 260 REDIM 263 REM 680 RESET 635 RESTORE 265 RESUME 373 RIGHT$ 225 RMDIR 682 RND 292 RSET 636 RTRIM$ 639 RUN 683 SADD 768 SCREEN (Function) 453 SCREEN (Statement) 454 SEEK (Function) 640 SEEK (Statement) 642 SELECT CASE 143 Set NextStatement 810 SETMEM 721 SGN 294 SHARED 186 SHELL 686 SIN 295

SQR 296 STATIC 189 STICK 504 STOP 688 STR$ 229 STRIG 507 STRIG ON/OFF/STOP 509 STRING 80 STRING$ 230 SUB 191 SWAP 81 SYSTEM 690 TAB 338 TAN 297 TIME$ (Function and statement) 386 TIMER 388 TIMER ON/OFF/STOP 389 Toggle Breakpoint 811 Trace On 812 TROFF, TRON 814 TYPE ... END TYPE 83 UBOUND 267 UCASE$ 233 UEVENT ON/OFF/STOP 375 UNLOCK 645 VAL 234 VARPTR, VARPTR$ 772 VARSEG 776 VIEW 460 VIEW PRINT 342 WAIT 724 Watchpoint 816 WHILE ...WEND 113 WIDTH (File I/O) 648 WIDTH (Screen) 344 WIDTH LPRINT 539

PEEK 714

SINGLE 78

WINDOW 464

PEN 499 PEN ON/OFF/STOP 502 PLAY (Function) 479 PLAY (Statement) 480

SLEEP 384 SOUND 487 SPACE$ 227 SPC 335

WRITE 347 WRITE # 650 XOR 147

PUBLISHEDBY Microsoft Press A Division of Microsoft Corporation One Microsoft Way Redmond, Washington 98052-6399 Copyright © 1990 by The Waite Group All rights reserved. No part of the contents of this book may be reproduced or transmitted in any form or by any means without the written permission of the publisher. Library of Congress Cataloging-in-Publication Data The Waite Group's Microsoft QuickBASIC bible / Mitchell Waite ... ret al.l. em. p. Includes index. ISBN1-55615-262-0 1. BASIC (Computer program language) 2. Microsoft BASIC (Computer program) I. Waite, Mitchell. II. Waite Group. QA76.73.B3W333 1990 005.26'2--dc20 90-43927 CIP Printed and bound in the United States of America.

5 6 78 9

AGF

54 3 2

Distributed to the book trade in Canada by Macmillan Publishing, a division of Canada Publishing Corporation. Distributed to the book trade outside the United States and Canada by Penguin Books Ltd. Penguin Books Ltd., Harmondsworth, Middlesex, England Penguin Books Australia Ltd., Ringwood, Victoria, Australia Penguin Books N.Z. Ltd., 182-190Wairau Road, Auckland 10, New Zealand British Cataloging-in-Publication Data available

Apple~ LaserWriter~

Macintosh't and Multiftnderf are registered trademarks and LaserShare TIl and QuickDraw TIl are trademarks of Apple Computer, Incorporated. Compuservev is a registered trademark of CompuServe, Incorporated. AT~ IBM~ Personal Systeml2~ and PSI2® are registered trademarks and PC/XTifllandXTTII are trademarks of International Business Machines Corporation. GW~ GW-BASIC~ Microsoftf MS-DOS~ and QuickCifll are registered trademarks and MACH20 TII and Microsoft QuickBASIC" are trademarks of Microsoft Corporation. As used in this book, DOS refers to the Microsoft MS-DOS operating system and the IBMversion of the MS-DOS operating system, also known as PC-DOS.

For Microsoft Press: Project Editor: Karen Marcus Technical Editor: Mary Dejong Manuscript Editor: Gary Masters Acquisitions Editor: Dean Holmes

For The Waite Group: Developmental Editor: Mitchell Waite Editorial Director: Scott Calamar Editor: Kay Nelson Editorial Assistant: Joel Fugazzotto

CONTENTS Foreword Preface

xi xiii

Acknowledgments

xvii

Introduction: A Task-Oriented Overview ofQUickBASIC

SECTION I

CORE

Chapter 1 CaNST DEFtype DOUBLE HEX$

Chapter 2 DO ... LOOP EXIT FOR ... NEXT

Chapter 3 AND + (Concatenation) EQV IF

Chapter 4 CALL(BASIC

procedures) CHAIN COMMON

Chapter 5 ASC CHR$ INSTR LCASE$ LEFT$

1

51

Variables and Types

53

INTEGER LET LONG OCT$

SINGLE STRING SWAP TYPE ... END TYPE

Flow Control

87

GOTO ON ... GOSUB

ON ... GOTO WHILE ...WEND

Decisions and Operators IMP MOD NOT

OR SELECT CASE XOR

Procedures

151

DECLARE (BASIC

procedures) DEFFN FUNCTION

Strings

117

GOSUB ... RETURN SHARED STATIC SUB

197

LEN MID$ (Function) MID$ (Statement) RIGHT$ SPACE$

STR$ STRING$ UCASE$ VAL

Chapter 6

Arrays and Data

DATA DIM ERASE

Chapter 7

LBOUND OPTION BASE READ

Math

ABS AlN CDBL CINT CLNG COS

Chapter 8

vi

299 SPC TAB VIEW PRINT WIDTH (Screen) WRITE

LINE INPUT LOCATE POS PRINT PRINT USING

349 ON UEVENT GOSUB RESUME UEVENT ON/OFF/STOP

ERR ERROR ON ERROR GOTO

Time (Timing, Date, and Time)

DATE$ (Function and statement) ON TIMER GOSUB

CIRCLE COLOR DRAW GET (Graphics) LINE PAINT

RND SGN SIN SQR TAN

Trapping and Errors

Chapter 10

Chapter 11

269

Simple I/O

ERDEV ERDEV$ ERL

SECTION II

REDIM RESTORE UBOUND

CSNG EXP FIX INT LOG RANDOMIZE

CLS CSRLIN INKEY$ INPUT INPUT$ (Keyboard)

Chapter 9

237

SLEEP TIME$ (Function and statement)

MULTIMEDIA Graphics

377

TIMER TIMER ON/OFF/STOP

391 393

PALETTE, PALETTE USING PCOpy PMAP POINT PRESET, PSET

The Waite Group's Microsoft QuickBASIC Bible

PUT (Graphics) SCREEN (Function) SCREEN (Statement) VIEW WINDOW

Chapter 12

Sound

BEEP ON PLAY GOSUB

PLAY (Function) PLAY (Statement)

Chapter 13

Light Pen and Joystick

ON PEN GOSUB ON STRIG GOSUB PEN

SECTION III

469

PEN ON/OFF/STOP STICK

DEVICES

Chapter 14

PLAYON/OFF/STOP SOUND

489 STRIG STRIG ON/OFF/STOP

513

Keyboard

515

KEY KEY(n) ON/OFF/STOP ON KEY(n) GOSUB

Chapter 15

Printer

527

LPOS LPRINT LPRINT USING WIDTH LPRINT

Chapter 16

Communications Port

541

COM ON/OFF/STOP ON COM GOSUB OPEN COM

Chapter 17 CLOSE CVD CVDMBF CVI CVL

CVS CVSMBF EOF FIELD FILEATTR FILES FREEFILE GET (File I/O) INPUT #

Files

559

INPUT$ (File I/O) LINE INPUT # LOC LOCK LOF LSET LTRIM$ MKD$ MKDMBF$ MKI$ MKL$ MKS$ MKSMBF$ NAME

OPEN PRINT # PRINT # USING PUT (File I/O) RESET RSET RTRIM$ SEEK (Function) SEEK (Statement) UNLOCK WIDTH (File I/O) WRITE #

Contents

vii

SECTION IV Chapter 18

655

DOS and Program Management RMDIR RUN SHELL STOP SYSTEM

ENVIRON$ IOCTL IOCTL$ KILL MKDIR REM

CHDIR CLEAR : (Colon) COMMAND$ END ENVIRON

693

Port and Memory

Chapter 19

POKE SETMEM WAIT

INP OUT PEEK

BLOAD BSAVE FRE

Chapter 20

727

Mixed Language

SADD VARPTR, VARPTR$ VARSEG

CALL INTERRUPT, CALL INTERRUPTX DECLARE (Non-BASIC procedures) DEFSEG

CALL (Non-BASIC procedures) CALL ABSOLUTE CALL INT860LD, CALL INT86xOLD

Chapter 21

653

DEVELOPMENT

779

Metacommands

$DYNAMIC $INCLUDE $STATIC

Chapter 22

Debugging

Add Watch Break On Errors Clear All Breakpoints Delete All Watch

SECTION V

viii

787

Delete Watch History On Instant Watch Set Next Statement

APPENDIXES

Toggle Breakpoint Trace On TROFF, TRON Watchpoint

819

Appendix A

Microsoft KnowledgeBase

AppendixB

CompuServe Files

AppendixC

Third-Party Routines

AppendixD

QuickBASIC for the Macintosh

The Waite Group's Microsoft QuickBASIC Bible

821

835

843 875

AppendixE

Statements Specific to OS/2 in Microsoft BASIC Compiler Versions6.0 and 7.0 883

AppendixF

Error Messages & Error Codes

AppendixG

Control Codes

AppendixH

ASCII Characters

Index

887

919 921

924

Contents

ix

Preface Our Approach We wrote this book with a special approach in mind. The idea is to allow you to access the most general information first, followed by more specific information. For example, if you are just getting started with QuickBASIC, you might want a general overview of the entire language-its advantages over other languages and its limitations, its power and its potential. The Introduction, "A Task-Oriented Overview of QuickBASIC," gives you this information in a style that is both comprehensive and readable. If you already know a version of BASIC, you probably want to identify those areas of QuickBASIC that are new and different. To this end, you can read the tutorials that introduce each chapter of the book; these sections summarize and discuss the usage of any commands and keywords that might be new to you. Finally, if you understand the big picture and you need to use a command, you'll want to read about it in greater detail. The reference sections of each chapter in this book discuss the purpose, syntax, and usage of every statement and function; they provide authoritative information about each entry, including programming tips and warnings; and they supply compatibility information that lets you immediately recognize which versions of BASIC support the statement or function. The discussions of statements and functions are arranged by subject area rather than alphabetically, as they are in most reference books. This organization lets you understand the relationships of the statements in a specific area, so you can quickly grasp their interactions rather than having to search for scattered entries throughout the book. We've also provided two alphabetic "jump" tables of keywords and concepts on the inside front and back covers of this book so that you can quickly focus on a specific topic.

How We Wrote This Book We developed the outline of this book by organizing all QuickBASIC keywords into 22 groups of related keywords. Next, we thoroughly studied each statement and function and agreed on the best example for it. Then we wrote the reference pages for each command. Short sample programs for the keywords were designed specifically to showcase the commands in an interesting, helpful, and useful manner. We then used the reference pages to produce the tutorial for each chapter. We condensed the most important elements of the 22 command categories into succinct, instructive summaries that show how you use the commands together. Then we further condensed the 22 tutorials into the Introduction, "A Task-Oriented Overview of QuickBASIC." Each step of this process further refined the information, pulling out the most salient facts and filtering out the finer details. Finally, we produced the "jump" tables

xiii

KEYWORDS, STATEMENTS, AND FUNCTIONS BY CATEGORY Variables and Types CaNST 63 DEFfype 67 DOUBLE 70 HEX$ 72 INTEGER 73 LET 74 LONG 76 OCT$ 77 SINGLE 78 STRING 80 SWAP 81 TYPE ... END TYPE 83 Flow Control DO... LOOP 95 EXIT 97 FOR ... NEXT 100 GOTO 105 ON GOSUB 108 ON GOTO 110 WHILE ...WEND 113 Decisions and Operators AND 124 + (Concatenation) 126 EQV 128 IF 130 IMP 135 MOD 137 NOT 138 OR 140 SELECT CASE 143 XOR 147 Procedures CALL (BASIC procedures) 159 CHAIN 161 COMMON 165 DECLARE (BASIC procedures) 173 DEF FN 176 FUNCTION 179 GOSUB ... RETURN 183 SHARED 186 STATIC 189 SUB 191

Strings ASC 210 CHR$ 211 INSTR 214 LCASE$ 216 LEFT$ 217 LEN 219 MID$ (Function) 221 MID$ (Statement) 223 RIGHT$ 225 SPACE$ 227 STR$ 229 STRING$ 230 UCASE$ 233 VAL 234 Arrays and Data DATA 248 DIM 250 ERASE 255 LBOUND 257 OPTION BASE 258 READ 260 REDIM 263 RESTORE 265 UBOUND 267 Math ABS 274 ATN 275 CDBL 277 CINT 278 CLNG 280 COS 282 CSNG 283 EXP 284 FIX 286

INT 287 LOG 288 RANDOMIZE 290 RND 292 SGN 294 SIN 295 SQR 296 TAN 297

Simple I/O CLS 305 CSRLlN 307 INKEY$ 309 INPUT 313 INPUT$ (Keyboard) 317 LINE INPUT 320 LOCATE 322 pas 325 PRINT 327 PRINT USING 330 SPC 335 TAB 338 VIEW PRINT 342 WIDTH (Screen) 344 WRITE 347 Trapping and Errors ERDEV 355 ERDEV$ 358 ERL 359 ERR 360 ERROR 362 ON ERROR GOTO 365 ON UEVENT GOSUB 368 RESUME 373 UEVENT ON/OFF/STOP 375 Time (Timing, Date, and Time) DATE$ (Function and statement) 380 ON TIMER GOSUB 382 SLEEP 384 TIME$ (Function and statement) 386 TIMER 388 TIMER ON/OFF/STOP 389 Graphics CIRCLE 402 COLOR 407 DRAW 413 GET (Graphics) 419 LINE 422 PAINT 426 PALETIE, PALETIE USING 431 PCOPY 435

PMAP 438 POINT 442 PRESET, PSET 04.44 PUT (Graphics) 447 SCREEN (Function) 453 SCREEN (Statement) 454 VIEW 460 WINDOW 464 Sound BEEP 477 ON PLAY GOSUB 478 PLAY (Function) 479 PLAY (Statement) 480 PLAY ON/OFF/STOP 484 SOUND 487 Light Pen and Joystick ON PEN GOSUB 496 ON STRIG GOSUB 497 PEN 499 PEN ON/OFF/STOP 502 STICK 504 STRIG 507 STRIG ON/OFF/STOP 509 Keyboard KEY 517 KEY(n) ON/OFF/STOP 519 ON KEY(n) GOSUB 523 Printer LPOS 531 LPRINT 534 LPRINT USING 537 WIDTH LPRINT 539 Communications Port COM ON/OFF/STOP 548 ON COM GOSUB 550 OPEN COM 552 Files CLOSE 570 CVD 571 CVDMBF 574 CVI 575 CVL 576 CVS 577 CVSMBF 578 EOF 579

FIELD 581 FILEATIR 583 FILES 585 FREEFILE 588 GET (File I/O) 589 INPUT # 592 INPUT$ (File I/O) 595 LINE INPUT # 597 LOC 601 LOCK 603 LOF 605 LSET 606 LTRIM$ 610 MKD$ 611 MKDMBF$ 613 MKI$ 614 MKL$ 615 MKS$ 616 MKSMBF$ 617 NAME 618 OPEN 620 PRINT # 626 PRINT # USING 630 PUT (File I/O) 632 RESET 635 RSET 636 RTRIM$ 639 SEEK (Function) 640 SEEK (Statement) 642 UNLOCK 645 WIDTH (File I/O) 648 WRITE # 650 DOS and Program Management CHDIR 661 CLEAR 662 : (Colon) 665 COMMAND$ 667 END 669 ENVIRON 670 ENVIRON$ 673 iocn 674 10CTL$ 676 KILL 677 MKDIR 679 REM 680 Rf\~DIR 682 RUN 683

SHELL 686 STOP 688 SYSTEM 690 Port and Memory BLOAD 700 BSAVE 703 FRE 706 INP 709 OUT 711 PEEK 714 POKE 718 SETMEM 721 WAIT 724 Mixed Language CALL (Non-BASIC procedures) 742 CALL ABSOLUTE 747 CALL INT860LD, CALL INT86XOLD 751 CALL INTERRUPT, CALL INTERRUPTX 755 DECLARE (Non-BASIC procedures)' 760 DEF SEG 765 SADD 768 VARPTR, VARPTR$ 772 VARSEG 776 Metacommands $DYNAMIC 782 $INCLUDE 783 $STATIC 785 Debugging Add Watch 802 Break On Errors 804 ClearAll Breakpoints 805 Delete All Watch 806 Delete Watch 806 History On 808 Instant Watch 809 Set Next Statement 81 0 Toggle Breakpoint 811 Trace On 812 TROFF, TRON 814 Watchpoint 816