Introduction to BASIC Programming Ken R. Hall, Ph.D. Ken R. Hall Consultants Portland, Oregon.
-
Upload
judith-preston -
Category
Documents
-
view
220 -
download
0
Transcript of Introduction to BASIC Programming Ken R. Hall, Ph.D. Ken R. Hall Consultants Portland, Oregon.
Introduction toBASIC Programming
Ken R. Hall, Ph.D.
Ken R. Hall Consultants
Portland, Oregon
Speaker’s Qualifications
• Ken Hall is a PICK/SHIMS consultant and owner of Ken R. Hall Consultants.
• Ken has over 25 years experience developing applications in PICK, Universe, and Unidata.
• Ken is a reseller of IBM U2 (Universe) and Raining Data database products.
• Ken has developed business applications for distributors, retailers, mail order houses, manufacturers, and leasing companies.
Learning Objectives
• As a result of this presentation, you will be able to:– Look at a BASIC program with an editor – Read the statements in a BASIC program– Know where to look for more information
when you don’t understand the program
Presentation Agenda
• Concepts and Terminology• Creating and Viewing
Programs• An Introduction to commonly
used BASIC statements• Where to find more
information about BASIC
UniVerse Database Concepts
• Multivalue database structure– Accounts and Files– Keys or Item-Ids– Variable length Record Structure
• Each subdivision has a separator character
– Records or Items• Fields or Attributes
– Values within Fields» Subvalues within Values
Terminology of PICK/BASIC
• Statements – a line of BASIC codeCUST.NO = CUSTOMER.REC<1>
• Constants and Literals – things that don’t changeOK.RESPONSE = “YES”
• Assignment Statements – changing valuesNUMBER.PRODS = 0
• Functions – things available from the systemTODAY = DATE()
• Operators – symbols that associate variables– Arithmetic, Logical, or String
+, -, *, /; #, =, GE, LE, LT, GT; :
Creating and Viewing Programs
• Create a File to store programs– CREATE.FILE YOURBP
• Naming a program• Use the Editor, ED or WED, to create/edit a program
– ED YOURBP YOUR.PROGRAM
• Compile the program with BASIC command– BASIC YOURBP YOUR.PROGRAM
• Activate the program with RUN command– RUN YOURBP YOUR.PROGRAM
• Activate the program with CATALOG command– CATALOG YOURBP YOUR.PROGRAM
Fundamental BASIC Statements
• PROMPT• PRINT• CRT or DISPLAY• INPUT• END• STOP• IF … THEN … ELSE• LEN(), ABS(), DATE(),TIME• OPEN• READ• WRITE• GO or GOTO
• * comments for clarity
• * looping• FOR
• NEXT
• LOOP
• UNTIL or WHILE• REPEAT
• * finding records
• SELECT
• READNEXT
Adding Comments for Clarity
• Comment lines start with *, !, or REM– * PROGRAM TO PRINT INVOICES FOR XYZ COMPANY– ! This line is also a comment
• Programs often start with comments that explain the purpose of the program and the author
• Comment lines can be used as spacers for clarity– *– * TODAY is a constant to store the current date– TODAY = DATE()– *
• Comments document modifications to the program
Simple Input of Information
• PROMPT defines the character displayed when user input is requested by the program– * send the colon when input is requested– PROMPT ‘:’
• INPUT requests user input from the keyboard– Puts prompt character at current cursor position– Input is completed by hitting Enter key – INPUT CUSTOMER.NAME
• Input can be positioned and/or formatted– INPUT @(ROW,COL):CUSTOMER.NAME
Output of Data
• PRINT sends data to either screen or printer– Controlled with PRINTER ON or PRINTER OFF
statements– PRINT “This is a test of output”– PRINT CUSTOMER.NAME
• CRT sends data to the screen– CRT YOUR.NAME
• Output can be positioned and/or formatted– PRINT @(ROW,COL):CUSTOMER.NAME “L#25”
Marking the END
• The END statement is used to:– Marks the end of the program
* the last line is belowEND
– Marks the end of a multi-line statementIF DAYS.PAST.DUE > “90” THEN PRINT “OVER 90 DAYS PAST DUE”END
• The STOP statement causes the program to terminate. * the next line exits this program after Q is typed IF DATA.INPUT = ‘Q’ THEN STOP END
Logical Control with IF … THEN
• Single line statement:IF X > “10” THEN PRINT “More than ten” ELSE PRINT “Ten or less”
• Multi-line IF statement:IF X > “10” THEN
PRINT “X is greater than ten”
END ELSE
PRINT “X is ten or less”
END
Logical Control with LOOP
• Single line LOOP statement: X = 0 LOOP X = X + 5 WHILE X < 100 DO PRINT “X is ”: X REPEAT * Go here when X is equal to or greater than 100
• Multi-line LOOP statement: X = 0
LOOP X = X + 5 WHILE X < 100 DO
PRINT “X is ”:X REPEAT
* Go here when X is equal to or greater than 100
OPEN file and READ data
• Use OPEN to gain acces to a fileOPEN ‘CUSTOMER’ TO CUST.FILE ELSE STOP
• Use READ to read a record from a fileCUST.NO = ‘1023’
READ CUSTOMER.REC CUST.FILE, CUST.NO THEN
CRT CUSTOMER.REC<1> ; * display customer name
END ELSE CRT ‘CUSTOMER ‘:CUST.NO:’ not found’
WRITE data to a file
• Use WRITE to save data to a recordWRITE CUSTOMER.REC ON CUST.FILE, CUST.NO
• Use WRITEV to save a variable in a field CUST.NO = ‘1023’
CUSTOMER.NAME = “ABC ELECTRIC CO.”
WRITEV CUSTOMER.NAME ON CUST.FILE, CUST.NO, 1
• Corresponding READV reads a field READV CUSTOMER.NAME FROM CUST.FILE, CUST.NO, 1 ELSE
CUSTOMER.NAME = ‘UNKNOWN’ END
Sample BASIC Program
* A simple program that opens a file and reads data PROMPT ''10: CRT 'Enter first file name: ': INPUT F1 IF F1 = '' OR F1 = 'X' OR F1 = "." THEN STOP OPEN F1 TO FILE1 ELSE CRT 'CANNOT open file ':F1 GO 10 END READ TEST.REC FROM FILE1, ‘TEST’ THEN CRT ‘TEST.REC IS ‘:TEST.REC END ELSE CRT ‘TEST IS NOT ON FILE’ END STOP END
PICK BASIC Book
• Jonathan E. Sisk'sPick/BASIC: A Programmer's Guide
Found on the web at: http://www.jes.com/pb/index.html
IBM UniVerse Documentation
• To view or get copy of UniVerse BASIC manual, follow the link below:
Found on the web at: http://www-306.ibm.com/software/data/u2/pubs/library/
Click on UniVerse version that you want.Choose “install doc set” to download the entire UV documentation set with installer.
Q&A