chap02 - QBASIC Chapter 2 QBASIC Chapter 2 QBASIC: An...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: QBASIC Chapter 2 QBASIC Chapter 2 QBASIC: An Introduction Created by Richard D. Taylor Illustrated by Saundra J. Taylor Creating a QBASIC Program Creating a QBASIC Program ­ QB Operating Environment - allows you to QB create, maintain, and execute Qbasic programs on your PC programs Creating a QBASIC Program Creating a QBASIC Program ­ General Characteristics of a Qbasic Program ­A program is composed of a sequence of lines ­Each line may contain one or more statements, Each up to a maximum of 255 characters up ­Statements instruct the PC to carry out an Statements action action ­Programmers type one statement per line and Programmers start of new line by pressing the Enter Key start Creating a QBASIC Program Creating a QBASIC Program ­ Keywords ­Let Statement - assignment statement, assigns a Let value to a variable value ­Let Commission = 0.18 * (1200 + 1500 - 75) ­ Variable Names and Constants ­Variable - represents a location, or address in Variable your computer’s memory which can change values as the program is executed values Creating a QBASIC Program Creating a QBASIC Program ­ Variable Names and Constants ­Variable name begins with a letter and may be Variable followed by up to 39 letters, digits, and decimal points points ­Keywords cannot be used as variable names ­Equal sign - means that the value of the variable Equal to the left of the equal sign is to be replaced by the final value of the expression to the right of the equal sign the Creating a QBASIC Program Creating a QBASIC Program Arithmetic Operator Meaning Examples of Usage Meaning of the Examples ^ Exponentation 2^3 Raise 2 to the third power * Multiplication 6.1 * A1 Multiply the value of the variable A1 by 6.1 / Division H / 10 Divide the value of the variable H by 10 Creating a QBASIC Program Creating a QBASIC Program Arithmetic Operator Meaning Examples of Usage \ Integer Division 5\3 MOD Modulo 5 MOD 3 + Addition 3.14 + 2.9 - Subtraction T - 35.4 Meaning of the Examples The integer quotient of 5 divided by 3 The integer remaider of 5 divided by 3 Add 3.14 and 2.9 Subtract 35.4 from the value of the variable T Creating a QBASIC Program Creating a QBASIC Program ­ The PRINT Statement ­instructs the PC to bring a result out from main instructs memory and display it on an output device memory ­ The END Statement ­instructs the PC to stop executing the program Creating a QBASIC Program Creating a QBASIC Program ­ Some Relationships between Statements ­the PRINT statement would display a result of the zero if earlier in the program we had failed to instruct the PC to assign a value to the variable Commission Commission ­PRINT A A=5 ­A = 5 PRINT A ­END END The INPUT Statement The INPUT Statement ­ provides for assignment of data to variables provides from a source outside the program during execution, data is supplied during execution of the program of ­ Input Prompt Message - input prompt Input message appears instead of question mark message The INPUT Statement The INPUT Statement ­ Form: INPUT variable INPUT “input message”, variable ­ Purpose: Provide for the assignment of values to Provide variables from an external device variables ­ Examples: ­INPUT A ­INPUT “What is your name?”; N$ The PRINT Statement The PRINT Statement ­ PRINT statements can be used to display PRINT messages that identify a program result messages ­LET A = 5 ­LET B = 3 ­PRINT A + B ­8 The CLS Statement The CLS Statement ­ Form: CLS ­ Purpose: Erases the information on the Erases output screen output ­ Example: ­CLS Coding and Documenting Coding and Documenting ­ Debugging - the process of removing errors Debugging from a program from ­ Coding Technique ­Coding Form - specially printed sheet of paper Coding divided into columns and rows divided ­Place the first letter of the new line in column A ­Space or blank - is a character, obtained by pressing Space the space bar on the keyboard the Coding and Documenting Coding and Documenting ­ Documenting a Program - The REM Statement ­ Form: REM comment ­ Purpose: to insert explanatory remarks or to comments in a program for documentary purposes purposes ­ Examples: ­REM Program #1 ­REM John Smith Coding and Documenting Coding and Documenting ­ Flowchart ­does not have to show a symbol for each statement ­not necessary to have an annotation symbol for each not REM statement REM Coding and Documenting Coding and Documenting ­ Multiple Statements per Line ­allow to write multiple statements per line, up to allow 255 characters 255 ­Example: ­ LET A = 5 + 4; PRINT A Getting Acquainted with the QB Getting Acquainted with the QB Operating Environment ­ Starting a Qbasic session ­Place Data Disk in the floppy disk drive ­Either double click on your Qbasic icon or at Either the DOS prompt, type QBASIC and press enter the ­ QB Survival Guide - online help system QB that answers your questions about QBASIC that Getting Acquainted with the QB Getting Acquainted with the QB Operating Environment ­ QBASIC Screen ­Menu Bar - the bar at the top of the QBASIC Menu screen, displays a list of menu names screen, ­View Window - the largest part of the screen View and contains the cursor and ­Immediate Window - narrow window below Immediate the view window used to execute statements as soon as entered soon Getting Acquainted with the QB Getting Acquainted with the QB Operating Environment ­ QBASIC Screen ­Status Line - the line at the very bottom of the Status screen that contains a list of the most used function keys and the line and column position of the cursor on the screen of Editing Acquainted with the QB Editing Acquainted with the QB Operating Environment ­ Dialog Box ­used to display messages and requested used information from you information ­Terminating a Qbasic session - click File on the Terminating menu bar and then click Exit on the File Menu menu Editing Qbasic Programs Editing Qbasic Programs ­ Editing - the process of entering and Editing altering a program altering ­ Deleting Previously Typed Characters ­Delete Key - to delete the character under the Delete cursor cursor ­Backspace Key - to delete the character to the Backspace left of the cursor left Editing Qbasic Programs Editing Qbasic Programs ­ Changing or Replacing Previously Typed Changing Lines Lines ­Insert mode - the cursor is a blinking underline Insert and the character under the cursor and those to the right are pushed to the right as you enter new characters in the line characters ­Overtype mode - the cursor is a blinking box Overtype and the character under the cursor is replaced by the one you type the Editing Qbasic Programs Editing Qbasic Programs ­ Adding New Lines ­Press the Enter Key to add new lines ­ Deleting a Series of Lines ­drag the mouse pointer from the first character drag to the last character in the series of lines and then press the Delete Key or click Edit on the menu bar and then Cut menu Editing Qbasic Programs Editing Qbasic Programs ­ Moving Text ­Move the mouse pointer to the beginning of the Move text you wish to move text ­Drag to select the text ­Click Edit on the menu bar and then click Cut ­Click on the new location Editing Qbasic Programs Editing Qbasic Programs ­ Copying Lines ­Move the mouse pointer to the beginning of the Move text you wish to paste text ­Drag to select the text ­Click Edit on the menu bar and then click Copy ­Click the new location, click Edit on the menu Click bar and then click Paste bar Executing Programs and Executing Programs and Hard Copy Output ­ Executing the Current Program ­clicking run on the menu bar and then clicking clicking start start ­Output screen - shows the results due to the Output execution of the current program execution ­ Listing Program Lines on the Printer ­Click File on the menu bar and then click Print ExecutingPrograms and Executing Programs and Hard Copy Output ­ Listing a Portion of the Program on the Listing Printer Printer ­use the mouse to highlight the lines in the use program you wish to print, click File on the menu bar, click Print, and be sure Selected Text Only option is selected Only Saving, Loading, and Erasing Saving, Loading, and Erasing Programs ­ File Specifications ­used to identify programs and data files placed used in auxiliary storage in ­ Examples: ­device name:\file folder\file name.extension ­A:\programs\lab2-1 Saving, Loading, and Erasing Saving, Loading, and Erasing Programs ­ Saving the Current Program to Disk ­to save a program to disk for later use, click on to File on the menu bar and then either Save or Save As Save ­Dirs/Drives box - includes a list of the disk Dirs/Drives drives and any file folders, or directories, that are part of the current drive are Saving, Loading, and Erasing Saving, Loading, and Erasing Programs ­ Loading a Program from disk ­click File on the menu bar and then Open on click the File menu the ­File box - lists the file names on the default File drive that have an extension of bas drive ­ Starting a New Program ­click File and then New The QB Survival Guide On­Line The QB Survival Guide On­Line Help System ­ A fully integrated online help system with fully instant access to any Qbasic question instant Summary Slide Summary Slide ­ Creating a QBASIC Program ­ The INPUT Statement ­ The PRINT Statement ­ The CLS Statement ­ Coding and Documenting ­ Getting Acquainted with the QB Operating Getting Environment Environment Summary Slide (cont.) Summary Slide (cont.) ­ Editing Qbasic Programs ­ Executing Programs and Hard Copy Output ­ Saving, Loading, and Erasing Programs ­ The QB Survival Guide On-Line Help The System System ...
View Full Document

This note was uploaded on 06/06/2011 for the course MIS 105 taught by Professor Grigoletti during the Spring '11 term at Moraine Valley Community College.

Ask a homework question - tutors are online