Introduction To QBasic
Introduction To QBasic
History of BASIC
BASIC was invented at Dartmouth College in 1964 by John Kemeny and Thomas Kurtz
The official languages at that time were, Fortran and Algol used only by professionals.
Thomas Kurtz / John Kemeny
History of Qbasic
Quick Beginner All Purpose Symbolic Instruction Code
Qbasic as a replacement for BASIC, BASICA & GWBASIC is a user friendly, includes : * full screen syntax checking editor * multifile & multi window editing * No compiling step * Full debuging facilities * pull down menues, simple but powerfull menu structure can be selected by using either Key Board or Mouse.
Terms
* ALGORITHM - An algorithm is a step-by-step list of directions that need to be followed to solve a problem. * SYNTAX The rules that govern the structure of source code. * INTERPRETER - An interpreter reads the source code one instruction or line at a time, converts this line into machine code and executes it. * COMPILER - A compiler reads the whole source code and translates it into a complete machine code program to perform the required tasks which is output as a new file.
Course Notes
Terms
* STATEMENT A FUNCTION procedure. Tells the computer what action to take. * VARIABLE A name for a value stored in the computers memory. It may be numbers or characters. Variable types: $ String, % Integer, & Long, ! Single, # Double, ## _FLOAT
Course Notes
Terms
* FLOWCHART - A flowchart is a type of diagram that represents an algorithm or process, showing the steps as boxes of various kinds, and their order by connecting these with arrows.
Course Notes
TEXTBOOK TERMS
* GLOSSARY - A glossary is a list of words and what they mean. They are usually found at the end of a book or report that uses hard or special words to read. * INDEX An index is a system used to make finding information easier. * APPENDIX Contains ASCII CODES
Course Notes
COURSE WORKFLOW
LECTURE Introduce programming commands. Discuss examples. (May not cover all new commands in lecture Follow your workbook) TEXTBOOK Read assigned chapters and work through exercises. Learn addition commands. Practice writing programs. Try and learn. LABS Write programs based on previous and new commands. Demonstrate to instructor.
Course Notes
Programming Process
The process of developing a computer program to solve a specific problem involves the following steps : Step : 1 : Problem Definition Step : 2 : Program Design Step : 3 : Program Coding Step : 4 : Program Execution Step : 5 : Program Testing and Debugging REPEAT STEP 5 Step : 6 : Program Documentation
REM Variable
REM Statement : Allows explanatory remarks to be inserted in a program. Syntax : REM text or text * Remarks are ignored when the program runs unless they contain meta commands, which control the allocation of dimensional arrays. ADVANCED PROGRAMMING * A remark can be inserted on a line after an executable statement if it is preceded by the single-quote (') form of REM or if REM is preceded by a colon(:).
CLS Statement
CLS Statement : Clears the screen. Syntax : CLS [{0 | 1 | 2}] CLS : Clears either the text or graphics viewport
PRINT Statement
PRINT : PRINT writes data to the screen or to a file. Must be within quotations (text). LPRINT: prints data on the printer LPT1. Syntax: PRINT [#filenumber%,] [expressionlist][{; | ,}] LPRINT [expressionlist] [{; | ,}]
END Statement
END Statement: Ends a program, procedure, block, or user-defined data type. Syntax : END [{DEF | FUNCTION | IF | SELECT | SUB | TYPE}] If no argument is supplied, END ends the program and closes all files. Used if want to stop the running of your program, even though there are more lines of commands. The END command will trick QBasic into thinking that there are no more lines to run and it will return you to the editor, this is applicable mainly in debugging.
RND Variable
RND Statement: Generates a pseudo-random number between 0 and 1. Pseudo-random because it allows starts in the same place. Syntax : RND
CLS PRINT RND vs. CLS DO PRINT RND SLEEP 2 CLS LOOP CLS DO PRINT 15 * RND SLEEP 2 CLS LOOP
vs.
COLOR Statement
Syntax: COLOR (foreground, background) Depends on screen modes (see p. 164) Default SCREEN MODE 0 - Text only: Color affects text (foreground) and text line (background).
Standard 16 colors 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
COLOR Statement
CLS COLOR 2 PRINT Welcome to Qbasic END
LOCATE Statement
LOCATE Statement: To set the cursor text cursor location, cursor visibility, and/or cursor size and height. Syntax: LOCATE [row][, [column][, [cursor][, [start][,[stop]]]]] Any of the parameters may be omitted, and any that are take on the respective previous setting. To change only one setting, the appropriate number of preceding commas must be included in the syntax. The default settings are: LOCATE 1, 1, 1, 16, 15 The CLS statement will cause the row and column parameters to return to the default, (1, 1), with exception to the overriding settings made by VIEW PRINT. LOCATE can be used to position the cursor at any location on the screen so that text characters can be displayed at that location using the PRINT statement. The row number ranges from 1 to 40 or 80, depending on the screen WIDTH. The column number ranges from 1 to 25, 30, 43, 50 or 60, depending on the screen height set by WIDTH:
LOCATE Statement
OUTPUT SCREEN: 25 rows (lines) x 80 columns (printing positions) CLS Statement clears screen and positions cursor at Location 1 ,1
SLEEP Statement
SLEEP Statement: A control flow statement that suspends execution of the program. Syntax : SLEEP [seconds]
If argument [seconds] is omitted program will suspend until a key is pressed or an enable event occurs. If argument is used, program will suspend until seconds elapse, a key is pressed or an enable event occurs whichever comes first.
DOLOOP Statement
DOLOOP Statement: A control flow statement that repeats a block of statements while a condition is true or until a condition becomes true. Syntax 1: DO [{WHILE|UNTIL} boolean expression}] [statement block] LOOP Syntax 2 : DO [statement block] LOOP [{WHILE|UNTIL} boolean expression}]
DO
False
LOOP
True
LOOP
Exit
Exit
DOLOOP Statement
DOLOOP
REM Press Ctrl|Break to end CLS DO COLOR 15*RND vs. PRINT Welcome SLEEP 2 CLS LOOP END
DO UNTILLOOP CLS A=0 DO UNTIL A = 10 A = A + 10 COLOR 15*RND PRINT Welcome PRINT A SLEEP 2 CLS LOOP CLS PRINT Program complete END