67x Filetype PDF File size 0.94 MB Source: upload.wikimedia.org
QBasic en.wikibooks.org June 11, 2019 Onthe 28th of April 2012 the contents of the English as well as German Wikibooks and Wikipedia projects were licensed under Creative Commons Attribution-ShareAlike 3.0 Unported license. A URI to this license is given in the list of figures on page 93. If this document is a derived work from the contents of one of these projects and the content was still licensed by the project under this license at the time of derivation this document has to be licensed under the same, a similar or a compatiblelicense, as stated in section 4b of the license. The list of contributors is included in chapter Contributors on page 89. The licenses GPL, LGPL and GFDL are included in chapter Licenses on page 97, since this book and/or parts of it may or may not be licensed under one or more of these licenses, and thus require inclusion of these licenses. The licenses of the figures are given in the list A A of figures on page 93. This PDF was generated by the LT X typesetting software. The LT X source E E code is included as an attachment (source.7z.txt) in this PDF file. To extract the source from the PDF file, you can use the pdfdetach tool including in the poppler suite, or the http://www. pdflabs.com/tools/pdftk-the-pdf-toolkit/ utility. Some PDF viewers may also let you save the attachment to a file. After extracting it from the PDF file you have to rename it to source.7z. A Touncompress the resulting archive we recommend the use of http://www.7-zip.org/. The LT X E source itself was generated by a program written by Dirk Hünniger, which is freely available under an open source license from http://de.wikibooks.org/wiki/Benutzer:Dirk_Huenniger/wb2pdf. Contents 1 QBasic/Print version 3 2 Introduction 5 3 Basic Input 7 3.1 6INPUT.BAS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 3.2 INPUT # and LINE INPUT . . . . . . . . . . . . . . . . . . . . . . . . . . 8 4 Text Output 9 4.1 Your first QBasic program: 1HELLO.BAS . . . . . . . . . . . . . . . . . . . 9 4.2 1HELLO.BAS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 4.3 PRINT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 4.4 2HELLO.BAS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 4.5 PRINT, Commas, Semicolons and CLS . . . . . . . . . . . . . . . . . . . . 10 4.6 3HELLO.BAS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 4.7 Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 4.8 4FACE.BAS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 4.9 LOCATEstatement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 4.10 5FACE.BAS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 4.11 COLOR statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 4.12 Color by Number . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 4.13 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 5 Basic Math 13 5.1 Equation Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 5.2 7MATH.BAS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 5.3 Understanding 7MATH.BAS . . . . . . . . . . . . . . . . . . . . . . . . . . 14 5.4 8MATH.BAS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 5.5 Understanding 8MATH.BAS . . . . . . . . . . . . . . . . . . . . . . . . . . 14 5.6 9TIP.BAS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 5.7 Tip Calculator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 5.8 10OROP.BAS. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 5.9 Parentheses and Order of Operations . . . . . . . . . . . . . . . . . . . . . . 16 5.10 Random Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 5.11 11RND.BAS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 5.12 More on RND . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 6 Flow Control 19 6.1 Conditional execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 6.2 True or False . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 III Contents 6.3 IF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 6.4 IF...THEN...ELSE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 6.5 13 ELSEIF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 6.6 FOR...NEXT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 6.7 14FOR.BAS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 6.8 WHILE...WEND . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 6.9 15WHILE.BAS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 6.10 DO...LOOP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 6.11 12IF.BAS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 6.12 SELECT CASE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 7 Advanced Input 25 7.1 INKEY$. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 7.2 The keyboard buffer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 7.3 Scancodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 8 Subroutines and Functions 27 8.1 Purpose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 8.2 Procedure vs. Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 8.3 GOTOandGOSUB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 8.4 ONERROR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 8.5 Declaring a subroutine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 8.6 Declaring a function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 9 Arrays and Types 31 9.1 Built-in Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 9.2 User-defined type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 9.3 Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 9.4 Multidimensional array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 9.5 Non-zero base . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 10 Files 33 10.1 The OPEN statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 10.2 Input and output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 10.3 Reading the file from disk . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 10.4 Writing a file to the disk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 11 Advanced Text Output 37 11.1 Cursor manipulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 11.2 Color . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 11.3 Formatted printing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 12 Sound 39 12.1 BEEP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 12.2 SOUND . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 12.3 PLAY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 12.4 Simple Musical Keyboard In Qbasic . . . . . . . . . . . . . . . . . . . . . . 40 13 Graphics 43 IV
no reviews yet
Please Login to review.