Chapter 9 - Unit 3

Fundamentals of qbasic: commands and statements, class 6 - apc understanding computer studies, choose the correct option.

Which of the following is not a BASIC statement?

Reason — RUN is a command that is used to execute a BASIC program.

Which of the following commands is used to execute a BASIC program?

Reason — RUN command is used to execute a BASIC program.

Which of the following is correct about LET keyword?

It is optional for assignment statement.

  • All basic statements start with this keyword.
  • It helps to execute BASIC programs.
  • It makes the programming logic easier.

Reason — LET is an optional statement. Every BASIC program need not use LET statement.

Which of the following is the correct extension of QBASIC file?

Reason — All QBASIC programs are saved with the extension .bas.

Which of the following commands is used to save a BASIC program?

Reason — Save As command is used to save a BASIC program for the first time.

Fill in the blanks

The full form of QBASIC is Quick Beginner's All-Purpose Symbolic Instruction Code .

LET statement is used to assign a value to a variable.

The term used to correct errors in a program is called debugging .

F5 function key is used to execute a program in QBASIC.

REM is a non-executable statement.

The extension of BASIC program file is .bas .

The maximum number of characters in the primary name of a BASIC file is eight .

Using EXIT command, you can quit QBASIC and return to the desktop.

Statements are the set of instructions to a program.

Question 10

Save As option is used to store a program in the secondary memory for the future use.

Identify the errors

CLEAR LET A = 15 TAKE B = 10 P = (A + B) 2 DISPLAY P END

CLS LET A = 15 LET B = 10 P = (A + B) ^ 2 PRINT P END

CLS INPUT A = 10 LET B = 45 P = (A x B) / 5 + B PRINT P STOP

CLS LET A = 10 LET B = 45 P = (A * B) / 5 + B PRINT P END

Case-Study Based Questions

Your teacher has given an assignment where the values of the variables are given as:

M=8; N=5; P=6; Q=3

(a) P * Q + M - N

(b) ( P + Q ) / ( P - Q )

(c) P ^ 2 + M / N

(d) M * N + P / 2

Find the result of each of the above expression.

Your friend has doubt in writing some of the QBASIC expressions. Help him to write the expressions correctly for the following purposes:

(a) To divide the sum of p and q by the difference of p and q.

(b) To divide the product of a, b and c by their sum.

(c) To find the sum of m raised to the power 2 and n raised to the power 3.

(d) To subtract p from the sum of m and 5 and multiply the difference by 10.

(a) ( P + Q ) / ( P - Q )

(b) ( A * B * C ) / ( A + B + C )

(c) M ^ 2 + N ^ 3

(d) ( ( M + 5 ) - P ) * 10

Explain the meaning

Explain the meaning of the following commands/statements with reference to QBASIC:

  • New — It allows the user to clear the working memory for fresh storage of the next program.
  • Open — It allows the user to open an existing program which is already stored in the main memory of the computer.
  • Save As — It allows the user to save the current program in the computer's memory for future use.
  • Print — It allows the user to get a hard copy of the current program.
  • Exit — It allows the user to quit QBASIC and return to the desktop.

Define the following

This command is used in QBASIC to execute any program or to see the output of the program. This can also be done by pressing F5, a function key. The output of the program is displayed on the output screen.

It is advised to see the output of a program on a clear screen. CLS command is used at the beginning of the program to allow the user to study the desired output of the program.

LET statement is used to assign a value to a variable. This statement can be used to assign a numeric or string constant to a variable.

Syntax: LET <variable> = <constant or variable or expression>

REM statement is used to write remarks about any program which basically shows the purpose of a program. It is a non-executable statement. Hence, the computer will ignore the content of the REM statement at the time of execution.

Syntax: REM <comment about the program>

PRINT statement is used to display any data, value, or message on the screen. It can be used to display a message, the value of variables or any statement with comma or a semi-colon. For example: PRINT "HELLO" PRINT A, B

Write down all the steps to perform the following tasks in QBASIC

Write a new program

To write a new program, follow these steps:

Step 1 — Click 'QBASIC' icon on the desktop or the taskbar. OR Click 'Start' and type QBASIC in the search box followed by clicking QBASIC app. The QBASIC window opens on the screen.

Step 2 — Press 'ESC' key to clear the dialog box appearing on the screen.

Step 3 — Select the 'File' menu. Now, click the option 'New'.

The QBASIC screen will now be ready to write the program.

Save a program

To save a program, follow these steps:

Step 1 — Click 'File' and select 'Save As' from the drop-down menu. The 'Save As' window appears on the screen.

Step 2 — Select a directory/drive where you want to store the file.

Step 3 — Write the file name in the 'File Name' box

Step 4 — Click 'OK'.

The file will be saved in the desired location.

Get the hard copy of a program

To get the hard copy of a program, follow these steps:

Step 1 — Open the program whose hard copy is required.

Step 2 — Click 'File' and select 'Print' option from the drop down menu. Print window will appear.

Step 3 — Select the printer, page layout, number of copies required etc. and click 'Print' option.

The program will be printed.

Save the current program

To save the current program, follow these steps:

Step 1 — Click 'File' menu.

Step 2 — Select 'Save' option from the drop down menu.

The current program file will be saved.

Exit QBASIC platform.

To exit QBASIC platform, follow these steps:

Step 1 — Click 'File' and select 'Exit' from the drop down menu.

Step 2 — Press 'Enter' key.

Step 3 — If you have made any changes to the current program, the system will ask for confirmation from the user. Click 'Yes', 'No' or 'Cancel' according to your need.

QBASIC platform will close and return to the desktop.

Distinguish between

RUN and PRINT

RUNPRINT
This command is used in QBASIC to execute a program or to see the output of the program.This command is used to display any data, value or message on the screen.

Program Screen and Output Screen

Program ScreenOutput Screen
Program screen is used for writing or editing a program.Output screen shows the output of a program when the program is run.

Solutions to Unsolved Programs on LET & PRINT

Write a program in QBASIC to greet your friend on the occasion of New Year by using PRINT statement. The output of the program is shown as:

There are 28 boys and 22 girls in your class. Write a program in QBASIC to find the percentage of boys and girls in the class.

The base and height of a triangle are 15 cm and 10 cm respectively. Write a program in QBASIC to calculate the area of the triangle. (Hint: Area of a triangle = 1 / 2 * base * height)

A salesman sold 14 chairs at the rate of ₹ 275 each and 3 tables at the rate of ₹ 650 each. Write a program in QBASIC to calculate the total sale.

Write a program in QBASIC to calculate the area and circumference of a circle with a radius of 14 cm. (Hint: Area of a circle = 22/7 * r 2 , Circumference = 2 * 22/7 * r)

Write a program in QBASIC to find the value of the given expressions when a = 10, b = 5, c = 2.

  • a 2 +b 3 +c 4
  • (a - b + c) 2

In a class of 60 students, 90% are present. Write a program in QBASIC to calculate the number of students present and absent.

The rate of petrol is ₹ 47.60 per litre. You paid ₹ 250 to the pump attendant and asked for 5 litres of petrol to be filled in the tank. Write a program in QBASIC to calculate the cost of petrol and the amount of money refunded.

In a book fair, you purchased the following books:

Harry Potter Books : ₹ 950 English Dictionary : ₹ 1200 Encyclopedia : ₹ 1600

You gave an amount of ₹ 4000 to the shopkeeper. Write a program in QBASIC to calculate the total amount to be paid to the shopkeeper and the money refunded by him.

'LEXPO' announces 25% discount on all leather items. You purchased a leather bag that costs ₹ 660 and a belt priced ₹ 160. Write a program in QBASIC to calculate the amount to be paid to the shopkeeper.

ICSE/ISC Textbook Solutions Class - 6 Concise Biology Selina Solutions Class - 6 Veena Bhargava Geography Solutions Class - 6 Effective History & Civics Solutions Class - 6 APC Understanding Computers Solutions Class - 7 Concise Physics Selina Solutions Class - 7 Concise Chemistry Selina Solutions Class - 7 Dalal Simplified Middle School Chemistry Solutions Class - 7 Concise Biology Selina Solutions Class - 7 Living Science Biology Ratna Sagar Solutions Class - 7 Around the World Geography Solutions Class - 7 Veena Bhargava Geography Solutions Class - 7 Effective History & Civics Solutions Class - 7 APC Understanding Computers Solutions Class - 8 Concise Physics Selina Solutions Class - 8 Concise Chemistry Selina Solutions Class - 8 Dalal Simplified Middle School Chemistry Solutions Class - 8 Concise Biology Selina Solutions Class - 8 Living Science Biology Ratna Sagar Solutions Class - 8 Around the World Geography Solutions Class - 8 Veena Bhargava Geography Solutions Class - 8 Effective History & Civics Solutions Class - 8 APC Understanding Computers Solutions Class - 8 Kips Logix Computers Solutions Class - 9 Concise Physics Selina Solutions Class - 9 Concise Chemistry Selina Solutions Class - 9 Dalal Simplified ICSE Chemistry Solutions Class - 9 Concise Biology Selina Solutions Class - 9 Total Geography Morning Star Solutions Class - 9 Veena Bhargava Geography Solutions Class - 9 Total History & Civics Solutions Class - 9 APC Understanding Computers Solutions Class - 9 Kips Logix Computers Solutions Class - 10 ML Aggarwal Mathematics Solutions Class - 10 Concise Physics Selina Solutions Class - 10 Concise Chemistry Selina Solutions Class - 10 Dalal Simplified ICSE Chemistry Solutions Class - 10 Concise Biology Selina Solutions Class - 10 Total Geography Morning Star Solutions Class - 10 Veena Bhargava Geography Solutions Class - 10 Total History & Civics Solutions Class - 10 APC Modern History & Civics Solutions Class - 10 APC Understanding Computers Solutions Class - 10 Sumita Arora ICSE Computers Solutions Class - 10 Kips Logix Computers Solutions Class - 11 APC Understanding Computers Solutions Class - 12 APC Understanding Computers Solutions ICSE/ISC SOLVED QUESTION PAPERS ICSE Class 10 Computers Solved 10 Yrs Question Papers Sample Papers ICSE Class 10 Computer Applications ICSE Class 10 Physics Solved 10 Yrs Question Papers Sample Papers ICSE Class 10 Physics ICSE Class 10 Chemistry Solved 10 Yrs Question Papers Sample Papers ICSE Class 10 Chemistry ICSE Class 10 Biology Solved 10 Yrs Question Papers Sample Papers ICSE Class 10 Biology Class - 12 ISC Computer Science Solved Practical Papers Class - 10 CBSE Computer Applications Solved Question Papers Class - 10 CBSE Computer Applications Solved Sample Papers Class - 10 CBSE Science Solved Question Papers Class - 12 CBSE Computer Science Solved Question Papers STUDYLIST Java Pattern Programs Java Series Programs Java Number Programs (ICSE Classes 9 / 10) Java Number Programs (ISC Classes 11 / 12) Output Questions for Class 10 ICSE Computer Applications Algorithms & Flowcharts for ICSE Computers ICSE Class 8 Computers Differentiate Between the Following CBSE Textbook Solutions Class - 8 NCERT Science Solutions Class - 9 NCERT Mathematics Solutions Class - 9 NCERT Science Solutions Class - 9 NCERT Geography Contemporary India 1 Solutions Class - 9 NCERT History India & Contemporary World 1 Solutions Class - 9 Sumita Arora Computer Code 165 Solutions Class - 9 Kips Cyber Beans Computer Code 165 Solutions Class - 10 NCERT Mathematics Solutions Class - 10 NCERT Science Solutions Class - 10 NCERT Geography Contemporary India 2 Solutions Class - 10 NCERT History India & Contemporary World 2 Solutions Class - 10 NCERT Democratic Politics 2 (Civics) Solutions Class - 10 Sumita Arora Computer Code 165 Solutions Class - 10 Kips Cyber Beans Computer Code 165 Solutions Class - 11 CBSE Sumita Arora Python Solutions Class - 12 CBSE Sumita Arora Python Solutions Class - 12 CBSE Preeti Arora Python Solutions Class - 12 NCERT Computer Science Solutions Class - 12 CBSE Informatics Practices Sumita Arora Solutions Class - 12 CBSE Informatics Practices Preeti Arora Solutions Company About Us Contact Us Privacy Policy Terms of Service Copyright © KnowledgeBoat 2024

Tuts Master 😉

QBasic Tutorial: QBasic Programming for Dummies

Introduction to qbasic.

Quick Beginners, All-Purpose Symbolic Instruction Code is a high-level programming language developed by Microsoft Corporation, the USA in 1985. It is modular programming, where programming is divided into different modules or procedures.

Q BASIC uses English like words and Mathematical symbols to write programs. Once you learn QBASIC programming it will be helpful to learn another high -level programming languages such as C, C++, Java, PHP, Dot-Net, etc.

[button color=”red” size=”big” link=”https://namecheap.pxf.io/c/2001466/1291734/5618″ icon=”” target=”true” nofollow=”true”]Don’t miss: .COM for just $0.98![/button]

QBasic, a short form of Quick Beginners All purpose Symbolic Instruction Code, is an integrated development environment and interpreter for a variety of BASIC programming languages which are based on QuickBASIC

Modes of Operation

The various ways in Q BASIC can be operated for obtaining the result:

  • View Window Mode: – The (upper) layer part of the full screen.
  • Immediate Window Mode: – The small window of the bottom of the editing window.

Q BASIC Statements and Its Purpose

CLS  is used to Clear the display screen. Rem  is used to writing remarks or explanation of the program.

Input  is used to supply or input data from the keyboard.

where prompt message tells the user what type of data is to be entered. Let  is used to assign the value of an expression to a variable. It is an optional statement. Syntax: Let Variable=Expression

Print  is used to display output on the screen in the desired alignment with some spacing in limited ways. It displays data, the value of variable or expression on the screen.

Const  is a non-executable statement that declares one or more symbolic constants.

The END  is used to terminate the Q Basic Program. A statement  is an instruction within a program. The four types of statements are;

  • Declaration Statement
  • Assignment Statement
  • Control Statement
  • Input/Output Statement

The command  is the instructions to the computer to do something to a program as printing, saving etc.

Keywords  are special words that have a special purpose and meaning in Q Basic. Some of the keywords are CLS, REM, PRINT. AND, OR, LEN, WHILE, etc.

Variables and Its Types

A variable is a symbolic unique name that occupies space in the computer memory for storing data temporarily. It can simply be said as a thing whose values keep on changing during the execution of a program. A value of a variable can be changed due to the execution of the programs.

1. String Variable:

It is a name or reference that stores alphanumeric characters. It contains dollar sign $, for example, R$, NI$, etc. Any types of declaration characters are not allowed in the variable name.

2. Numeric Variable

It is the name or reference which stores a positive or negative number.  There is four types of Numeric Variable.

  • Integer- percentage sign %
  • long Integer- ampersand sign &
  • Single precision- exclamation !
  • Double precision- has tag #

Constants and Its Types:

Constants are the data of values in a program, that may be a letter, number or special characters. Its value doesn’t change during the execution of the program.

1. String Constant

An alphanumeric data enclosed in double quotes is called string constant. It may be a word, number, blank space, special character, etc. for example: “Dhading”.”Mahendranagar”.

2. Numeric Constant

A number with or without a decimal point that is not enclosed inside double quotes. All positive and negative and decimal numbers are numeric constants. for example: 5,-7,7426.42etc

Rules For Naming The Variable

  • a. A variable must be up to 40 characters long.
  • b. It must begin with a letter.
  • Variable word cant is reserved word.

Accumulator

It is a variable in which the intermediate value of another variable is stored. It helps to find the sum of all values assigned to the particular variable. Example

Control Structure

The process of a departure of the control of the program Conditionally or Unconditionally from its sequential flow depending upon the result of the condition is known as Branching or Jumping. Control Structure is the statement of the structure that is used to handle different conditions and iterations. It is used to control the flow of a program. They are Sequential Structure, Selection Structure, and Loop Structure.

Sequential Structure

A structure in which the statements are executed sequentially one after another without changing the flow of the program. Example,

Selection Structure

It is also known as a branching structure that allows you to transfer the program control from one part to another on the basis of a specified condition or without condition.

Types of Selection Structure:

If statement.

  • Select Case Statement

This is a decision-making statement that decides which statement has to be executed on the basis of the specified condition.

1. If…..Then Statement

It is a one-way decision-making statement that evaluates a condition and executes the statement if the result of the condition is true. Syntax,

If…..Then…Else Statement

It is the two-way decision-making statement that can decide which part of the computer it has executed when the condition is true or false. It executes one part of a program if the condition is true and another part if the condition is not true or false. Syntax:

Write a program to check whether the number is divisible by 4 and 5

If…..then…else if……else.

It is a multi-way decision-making statement that is used when there are two or more conditions to be evaluated. Syntax

Loop Structure

For……..next statement.

It repeats a block of statements a specified number of times. 1,2,3,4…..10

While…..Wend Statement

It executes a  block of statements repeatedly until the specified condition is true. 1,4,7,10…….25

Do…Loop Statement

It repeats a part of the program while a condition is true or until the condition becomes true. 100,90,80……up to 10

Nested Loop

The Loop inside the loop structure is called Nested loop. It contains an outer loop and inner loop. 7  7  7  7  7  7  7  7 6  6  6  6  6  6  6 5  5  5  5  5  5 4  4  4  4  4 3  3  3 2  2 1

This tutorial is also available in .TXT format

  • Introduction
  • Interacting with the computer
  • More Advanced Data Manipulation
  • Designing Applications
  • Beyond QBasic
  • Subject Index

In the early days of programming, it was usually the scientific elite doing the programming and they were usually trained above and beyond the average American to do their programming work. It was not until 1964 at Dartsmouth college that the Beginner' s All-purpose Symbolic Instruction Code would be introduced -- more commonly known as BASIC. Using common English to perform processor tasks, BASIC became quickly popular, although it was disliked by programmers of more "low-level" languages such as assem bly and FORTRAN. In 1985 Microsoft released their own version of BASIC called QBasic with their MS-DOS 5.0 operating system. Since then, nearly every PC user owns their own copy of QBasic, making it a widely known language.

QBasic is a very simple language to pick up, and yet it can accomplish a great deal. Granted you will probably never write Doom or Word Perfect with QBasic, but it has it's strong points. One of them is to introduce people to programming without having to worry about the internal workings of the computer. It's simple to create games, business applications, simple databases, and graphics. The best aspect of the language is it's close resemblance to English.

This small tutorial introduces the simple concepts of programming to get you started, so if you already know another language or are already familiar with programming, you may want to skim through the first couple sections. Good luck!

A variable, simply defined, is a name which can contain a value. Programming involves giving values to these names and presenting them in some form to the user. A variable has a type which is defined by the kind of value it holds. If the variable holds a number, it may be of integer, floating decimal, long integer, or imaginary. If the variable holds symbols or text, it may be a character variable or a string variable. These are terms you will become accustomed to as you continue programming.

Here are some examples of values a variable might contain:

The first is a string. Strings contain text. The last four are number types. But the computer does not know what kind of value you are trying to give a variable unless you tell it! There are two methods of telling the computer what kind of variable you are using:

1. Explicitly declare the variable AS a type. This is done by using the DIM statement. Say you wanted to make a variable called number which would contain an integer (whole number, no digits after the decimal point). You would do it like this:

Then you would use that variable as an integer. The word DIM actually originates from the word Dimension, but you won't see why until we discuss the topic of arrays.

2. Put a symbol after the variable name which is defined as representing that type. QBasic has a set of symbols which represent each variable type:

Appending one of these symbols to the name of a variable when you use it in the program tells the computer that you are using it as that type. This topic of data types is actually a difficult concept to grasp for newcomers to programming. The most com mon error in QBasic is the infamous Type Mismatch which you will see a lot. This means that you are trying to put a value into a variable of the wrong type. You might be trying to put the letters "hi there" into an integer variable. If you don't define th e type of the variable, then QBasic assumes it is of the Single type, which can often yield unexpected results. I personally prefer to use the type symbols after variable names, but some explicitly declare them usually at the head of their programs.

You know what a variable is and how to control them, it's time you learned some programming. QBasic (like all other languages) is set up using pre-defined statements according to the syntax specified for that statement. It may be helpful to look in t he help index to learn a statement, although I've heard many complaint's that the help index is too hard. Indeed it is too hard for new programmers, but as you learn more and more statements and their syntaxes, you'll become accustomed to the index and u se it as a casual reference. Lets make a program that prints some text on the screen. Type qbasic at the DOS prompt and enter the following program.

The first statement -- CLS -- stands for "clear screen." It erases whatever was on the screen before it was executed. PRINT simply displays its argument to the screen at the current text cursor location. The argument in this case is the text enclosed in quotes. PRINT displays text within quotes directly, or it can display the value of a variable, like this:

This will yield the output; The value of a is 50 and the value of b is 100 . The semicolons indicate that the next time something is printed, it will be right after where the last PRINT statement left off. Remember that PRINT prints literally what is inside quotes, and the value of the variable which is not in quotes. a% and b% are integers containing values in this example, and their values are printed using the PRINT statement. Say you want to interact with the user now. You'll need to learn a statement called INPUT . INPUT displays a prompt (the first argument) and assigns what the user types in to a variable (the second argument)

This firsts asks the user for their name and assigns it to the string variable yourName$. Then the age is requested, and the result is printed in a sentence. Try it out! So what happens if you input I DON'T KNOW for the age prompt? You'll get a wei rd message that says REDO FROM START . Why? The program is trying to assign a string (text) to an integer (number) type, and this makes no sense so the user is asked to do it over again. Another cornerst one of programming is the conditional test. Basically, the program tests if a condition is true, and if it is, it does something. It looks like English so it's not as hard as it sounds.

The user is given a set of options, and then they input a value which is assigned to the variable selection%. The value of selection% is then tested, and code is executed based on the value. If the user pressed 1, it prints hello , but if they pressed 2, it prints nice tie . Also notice the text after the ' in the code. These are remark statements. Anything printed after a ' on a line does not affect the outcome of the program. Back to the actual code -- but what if the user doesn't i nput 1 or 2? What if they input 328? This must be taken into account as part of programming. You usually can't assume that the user has half a brain, so if they do something wrong, you can't screw up the program. So the ELSE statement comes into play. The logic goes like this: IF the condition is true, THEN do something, but if the condition is anything ELSE, then do something else. The ELSE statement is used with IF...THEN to test if a condition is anything else.

That's a fairly simple example, and real life things will be much more complex. Lets try a "real life" program. QBasic is capable of fairly sophisticated math, so lets put some of it to use. Say your Algebra teacher tells you to find the areas of th e circles with some given radii, and he gives you a sheet with hundreds of radii. You decide to boot up your computer and write the following program:

First, we're defining the variable pi. It's a single number, which means that it can be a fairly large number with some decimal places. The exclamation mark tells QBasic that pi is of the single type. Next, the user is prompted for the radius of the ir circle. Then the area is calculated. The * means "times," and the ^ (carrot) means "to the power of." radius! ^ 2 means "radius squared." This could also be written as pi! * radius! * radius!. There's one big problem with that program. Th e teacher gave you a sheet with hundreds of radii. For every radius, you must run the program over again. This is not practical. If we had some kind of a loop until we wanted to quit that just kept on repeating over and over it would be much more useful . Of course, QBasic has the means of performing this feat. Loop structures. They start with the statement DO , and end with the statement LOOP . You can LOOP UNTIL or WHILE , or DO UNTIL or WHILE a condition is true. Another option (which we will use) is to break out of the loop manually as soon as a condition is true. Lets revise the previous code:

Now we can end the program by entering -1 as the radius. The program checks the radius after the user inputs it and checks if it is -1. If it is, it exits the loop. If it isn't it just keeps going it's merry way. The PRINT with no a rguments prints a blanks line so we can separate our answers. I highly recommend entering this program into QBasic just so you can see exactly how it works.

Say you want to print something in a certain pre-defined format. Say you want to print a series of digits with only 2 places after the decimal point and a dollar sign before the first digit. To do this requires the PRINT USING statement, which is very handy in applications for businesses. The PRINT USING statement accepts two types of arguments. The first is a string which has already been defined. This is a special type of string, in th at it contains format specifiers, which specify the format of the variables passed as the other arguments. Confused? You won't be. Here's a quick list of the most common format specifiers:

And these can be combined in a format string to make a user defined way to print something. So $$#,###.## will print a number with a dollar sign to the left of it. If the number has more than two decimal places, it is truncated to two. If it is mor e than four digits long to the left of the decimal place, it is also truncated to fit. To use a PRINT USING statement, you must first define the format string containing the format specifiers. Then you use PRINT USING, then the name of the format string, and variable values to fill the places defined in the format string. Here's a code example:

First, we get the item name, number of items, and cost per item from the user. Then we clear the screen and define the format string to be used. It contains a static length string (text that will be truncated if it is too long), up to 4 digits for th e quantity, 4 digits and two decimals for the item cost, and 7 digits and two decimals for the total cost. Then we print out some column headers so we know what each value will represent, and some nice lines to go under the column headers. Then the tota l cost is calculated by multiplying the number of items by the item cost. Finally, the four variable's values are displayed under the column headers using the PRINT USING statement.

There are numerous methods to manipulate data and present it to the user in QBasic. One is called an array. An array is a variable which can contain more than one value. For example, you might have an array called a , and yo u could assign data to the members of that array. There might be a value for a(1), and a different value for a(6). Before an array can be used, it must be declared. Arrays are declared with the DIM statement used in section 1. Here is an example of an array declaration:

There are now 100 different values that can be assigned to the array a , and they must all be integers. It could also look like this:

Using the symbol % for integer. We call the different values for the array members of the array. Array a has 100 members. Array members can be assigned values by using a subscript number within parentheses after the array name, like this:

And so on. Now you're probably wondering why the statement for declare is DIM . This comes from a term used in earlier programming languages that means dimension. That still doesn't answer the question... why not use the statement DECLARE ? Well, an array can have more than one dimension. Arrays with multiple dimensions have y members in the second dimension for every x member of the first dimension in the following algorithm:

So if the actual declaration looked like this:

You would have the following members to assign values to:

A two dimensional array is useful for tracking the status of each piece in a checkers game, or something of the like. Recall the last example program of section that we had a program that would ask the user for the item name, the item cost, and the qu antity of that item, the spit out the data just given in a nice format with the total in the right hand column. Well, with only one item, this program isn't very practical. But now with our newfound knowledge of arrays and the knowledge we already have of loops, we can create a somewhat useful application. The process will start with the program prompting the user for the number of items that will be calculated. Then the program loops for the number of times that the user entered at the beginning, ass igning the data entered into a member of an array we will declare. A variable called netTotal! will be displayed at the end of the program which will contain the total costs of the items. netTotal! will accumulate each time through the loop as the curre nt totalCost! is added to it. Type the following code:

This program is much larger than anything we've done as of yet. It is kind of a review of everything we've done so far and one additional feature: the FOR...NEXT loop. This kind of loop loops for the number of times specified. A value is given to a variable and the program loops until that variable is equal or greater than the number specified after the TO .

Will loop 10 times, printing the numbers 1 through 10. The loop ends with a NEXT statement followed by the variable the loop increments for. So in our program, we have loops with index numbers (i%) starting at 1 and increasing for every number between 1 and the totalItems%, which is given by the user in the first part of the program. After the user inputs the number of items that will be calculated, four arrays are DIMensioned. They are one dimensional arrays, so they aren't very comp lex. The first FOR...NEXT loop prompts the user for each item. Then the format string is defined and the column headers are printed. The second FOR...NEXT loop cycles through the members of the four arrays and prints the data u sing the format string. The data for each member was assigned in the first FOR...NEXT loop. Each cycle through the second loop, the totalCost! of the current item being printed is added to the variable netTotal!. The netTotal! is the total sum of the total costs. After the second FOR...NEXT loop, the net total is printed and the program ends.

Say we have a game and when the user makes a record score, they get to write their name on a list of the 10 best scores. But the next time the user plays the game, we want the name and position they recorded the last time they played to still be there . To do this, we must write to what is called a file, and then read it again later. If you are computer literate, then no doubt you know what a file is, and since you are using the internet to read this, I'm assuming you are. So we need to write to file . Before you can do anything to a file, you must open it, and there are different ways you can open a file, believe it or not. A file can be opened so you can read from it or write to it, or it can be opened and split into records like a database. Here is a quick table of the different ways you can open a file:

Input Read data from the file
Output Write data to the file
Append Write data to the end of a file
Binary Read from or write to a file in binary mode
Random Read from or write to a file which is split up in records like a database

The syntax for the OPEN statement is quite peculiar. It's arguments require us to specify a file name, an access type (the 5 types defined above), and a file number. When the file is open, QBasic recognizes i t by a number which we assign to the file when we open it. All references made to the file use this number. It can be any number from 1 to 255. An open statement may look like this:

We will be reading data from this file because it was opened for input. Back to our problem about the game scores. Lets set up a program which will ask for their name and give them a random score. Then it will put their name on the list at the approp riate place on the top 10 (if it makes the list). We'll call the file "top10.dat." But say when the user buys the game, there are already 10 names and scores in there. We write the following program to put default names and scores into top10.dat:

There are a couple strange features of this program that we have not seen yet. In the second line of the program the file is opened for output so we can write to it. In the fourth line of the program we get into some light string manipulation. A nam e is generated from the word player, and is concatenated with string form of the current loop number. You can concatenate two strings by using the + operator. The STR$ function returns the string representation o f the number passed to it. The opposite of the STR$ function is the VAL function, which returns the numeric value of the string passed to it. Lastly , the WRITE statement w rites to the file number specified as the first argument the values of the following arguments. Data is written to file in a format readable by the INPUT # statement which we will use in the actual program. We need this short program for th e big one to work so we can give the program data to read from, or else we will get a nasty INPUT PAST END OF FILE error when we try to run it. Note that the file should be closed when we are done with it by using the CLOSE state ment followed by the file number.

And now we come to the big program, as I have referred to it. It is quite large and complex, and I have not fully described all the statements used in it, so I have broken it down to five sections which I will describe in detail afterwards. Here, at l ast, is the code:

Section 1: The screen is cleared. The second line contains the statement RANDOMIZE TIMER . When dealing with random numbers, we must give the computer a number so it has something to base th e random number it will create from. This number is called the random seed generator. A random seed generator can be specified with the RANDOMIZE statement. For the seed, we need a number that will not be the same every time we run a progr am, so we decide to use the number of seconds which have elapsed since midnight. The TIMER statement accesses a system device called the system timer, and returns the current number of seconds which have elapsed since midnight. Since this n umber will change in each program we run, this can be used for the random seed. The variable yourScore% is given a random number from 0 to 1000. In the last part of section one, we declare two arrays with 10 members each.

Section 2: In the first line we open the file for input, so we can read from it. The second line appears to be very weird at first. We are starting a loop with the DO statement, and then a condition to do while. The function EOF tests the file number passed to the function -- in this case 1 -- and if the end of the file ( EOF ) has been encountered it returns true. So EOF(1) is true if we are reading the end of the f ile. But we are using the Boolean operator NOT , so we want to loop while the end of file condition is false. We want to do the loop while we are not reading from the end of file 1. You will learn more about Boolean operators ( NOT, AN D, OR, XOR , etc.) as you continue programming. Then we assign the current data in the file to the arrays we declared in section 1. The INPUT # statement is used to read from the specified file into the specified variable(s) until a co mma or carriage return is encountered.

Section 3: The main purpose of this section is to re-write the top 10 list if the player's randomly generated score places on the list. We do this by cycling through the list, and testing if yourScore% is greater than or equal to (>=) the c urrent playerscore% being tested. If it is, then we have to shift each existing score below the current one down one to make room for the new score being added. The user is congratulated and prompted for their name. The loop is then exited using the EXIT FOR statement, which then goes to section 4.

Section 4: This short section simply opens the file for output so we can write to it. Then we write each of the members of the array to file.

Section 5: In this final section we define the format string, print the headers, and then print all the members of the top 10 and their scores. And that's the end of the program!

Now on to a new topic, which will later become related to the previous. User defined types. Recall that a type is the type of value a variable can have, such as integer, string, long, double, or single. You can creat e your own types which contain one or more of the already defined types. Here is an example of a user defined type:

We have defined a new type, which consists of four data members, as I call them. We can now declare a variable of this type:

A variable of a user defined type is like an array, in that it can have more than one value assigned to it. But you can have an array of a variable of a user defined type as well, so things can get rather complex. Anyway, now that you have a user def ined type, you can assign values to the data members of that variable. Use a period to access a data member of a type, like this:

This could have been helpful in the last program we made with the top 10 list. We could have declared a user defined type called playerType, like this:

and then declared an array of variables of that type

That would have made our code more efficient, but not necessarily more readable. Notice when we declare a string in a user defined type that it seems as if we are multiplying it by a number. Actually, we the number after the * defines the maximum len gth of the string. You must define this because the size of a user defined type must be known by the computer. Any value assigned to this string data member which exceeds the length specified is truncated.

User defined types can serve more than to be efficient. They are the heart of the random access file mode, which is commonly used in database files. A database is a method of organizing large quantities of information in records and fields. In a rec ord, there are a set of fields which are constant in every record. A field's value changes from record to record, however. Just the name of the field remains constant. So how does this relate to user defined types? Well think of a variable of a user d efined type as a record in the database, and the data members fields of the records. Employee may be a record, and firstname, lastname, age, and wage may be fields. Values can be assigned to the fields in each record, thus constructing a database. A fi le opened for random access is organized in this fashion, with records split into fields. Each record in the random access file is given a record number which can be convenient in a database environment. In the OPEN statement for opening a random access file there is one extra argument. We must specify the length in bytes of how much space one record will occupy -- the record length. This can be easily taken by taking the LENgth of a variable defined as the user defined type we are going to use. So back to our employee example, we could use the LEN function to get the size in bytes of the employee variable, which is an employeeType. Here's the code:

LEN stands for length. You can also use the LEN function to get the number of characters in a string, but that is kind of irrelevant right now. So let's construct a simple database that will keep tra ck of the employees of a business.

I've split this program into sections again because that seems to work well for the larger ones.

Section 1: We're defining the user defined type and declaring a variable of that type.

Section 2: The first thing the user sees is a menu with the option to either create a new database (recordset) or view the existing one. The user is prompted to make a selection which is stored in the variable selection%.

Section 3: If the user chose option 1 -- create a new recordset -- then this code is executed. First we prompt the user for how many employees are in the company so we know how many times to go through a loop. Then we open the file, prompt the user for the data for each variable, and write the whole record to file. The record is written using the PUT statement. The first argument in PUT is the file number, the second is the record number, and the third is the data to be written to file. If no record number is specified for the second argument, the current file position is used, which will just append what we specify after what is already there. This works fine, so we don't need to worry about explicit record numbers. Notice that we are writing the whole employee variable to file. This is because we write records to file, and the whole variable contains the data for the data members (fields).

Section 4: If the user chooses to view the existing recordset, then we first open the file, define a format string for the printout, and print the headers. Next we have a loop until the end of file is encountered. Notic e the GET statement, which is used to read from a random access file. The first argument is the file number we want to read from, the second is the record number (which we are leaving blank because we can read from the current position [ CP] like we did in the PUT statement), and the third is the variable in which we read the data in to. This variable must be of the same type that we wrote with or else the types will be incompatible. You'd probably get a TYPE MISMATCH error if a different variable is used because the fields are not equal, so the program does not know what to assign the data to.

Well that's it for random access. If you have understood half of what I've said, feel good. You have a good knowledge of what QBasic is about. Now on to some more advanced programming!

Graphics programming in QBasic can get fairly complex. Lets start from the beginning. Your screen is made up of hundreds of pixels. The number of pixels horizontally and the vertically determines the resolution of you r monitor. In DOS you can be in one of any number of graphics modes, which define the current graphics resolution (pixels), text resolution (characters), number of colors, and number of video pages. There are 13 screen graphics modes in QBasic, and each has its different purpose. You can look in the help index in QBasic for a listing of the screen graphics modes and their specifications. Each of the aspects of a screen graphics type can be changed to create effects.

There are a number of graphics routines used in QBasic which allow a variety of graphical effects. Lets try a few:

The first line initializes the graphics mode to 12, which is 16 colors, 1 page of video memory, and 640x480 resolution.

LINE draws a line from one coordinate to another. The first optional argument after the coordinates (which are not optional) is the color. After that, a B ("box") or BF ("box fill") can be used to draw a box or a box filled with the color specified. The first coordinate can be omitted and the - left in to draw a line from the current graphics position (CP) to the relative coordinates specified. LINE -(100,0) will draw a line from the current g raphics position to 100 pixels to the right.

CIRCLE draws a circle with the center at the coordinates specified. The first argument (required) after the coordinates is the radius of the circle. Then comes the color. After that, if you want to draw an arc, is the starting angle of the arc in radians , then the ending angle of the arc. To make an arc, first touch up on your geometry, then recall that to convert from degrees to radians is PI (3.14159265) divided by 180. The last argument is used if you want to make an ellipse, and is the ratio of the y axis to the x axis. So CIRCLE (320,240), 20, 2, 3.1415, 0, .5 would draw an elliptical green arc with the center at the middle of the screen, starting at 180 degrees (PI) and going t o 0 degrees, with a compression ratio of 1 to 2 (x axis twice as big as the y). This looks like a wide smiley face mouth.

PSET fills a pixel at the screen coordinate you specify with the color you specify. In this case, yellow.

Finally, the DRAW statement. The DRAW statement has it's own commands which I strongly suggest you memorize. When we get in to scaling and rotation you will need to know your draw commands pretty well. The draw command in the above code example can be read as "color 15 (white), move without drawing to screen coordinate 100,400, draw left 5 units, draw up and right 5 units, draw down and right 5 units, and draw left 5 units." In other words, a tr iangle. A unit is set by the current scale mode, which by default is 4. Since default scale mode is 4, one unit represents 4 pixels. So our triangle is 40 pixels wide at the base.

There are 16 defined colors in QBasic, graphics mode 12. The COLOR statement sets the current color for text output. I highly recommend memorizing the colors as well. Run this program:

This will print out the 16 colors used in QBasic. 0 is black, so that obviously won't show up. An quick reference for colors while you're in the QBasic IDE (integrated development environment) is to look under the OPTIONS | DISPLAY menu. The colors listed there are in the QBasic order, starting with black and ending with bright white.

Now you know the basic graphics routines and their uses... lets make a couple programs that demonstrate them to a greater extent. First, a program which prompts the user for a radius, calculates the area and circumference, and draws the circle in a ra ndom color on the screen.

We first set the screen graphics mode and generate a random seed number based on the system timer. Then we prompt for the radius in a vivid bright white, and test to see if we should end the program. We then calculate the area and circumference, and p rint the results in yellow. Then we draw the circle from the middle of the screen at the radius given in a random color. This random color is set by first generating a random number from 0 to 14, adding 1 to it, and converting it to an integer with the INT function. The next line seems weird. The INKEY$ statement reads the keyboard and returns the string representation of the key pressed. We are looping while INKE Y$ is nothing, or in other words, while the user isn't pressing anything. The loop goes on forever until the user presses any key, and at this time a value will be given to INKEY$ which you might decide to use. The screen is then clea red for the next entry. If the user breaks the loop by entering -1 for the radius, we print Good Bye! in bright blue letters.

There are a lot more colors than just 16. In fact, you can change the values of each of the 16 colors to represent some other color that you specify. You do this with the PALETTE statement. The following applies to screen modes 12 and 13. This statement has two arguments: the color you want to change and the color you specify. Specifying a color is the hard part. Here is my version of the syntax of the palette statement

PALETTE color, blueValue * 256 ^ 2 + greenValue * 256 + redValue

color is the color you are changing. The _Values are numbers from 0 to 63 which specify the intensity of that color. You must use the multipliers after the values and use the addition operator to separate them. So lets make a program that fades the s creen in and out, from black to purple. (blue and red make purple).

We start by changing the value of black (0), which is the background color to purple, from one degree of blue + red to the next. Then we bring it back down to black by decreasing the blue + red value. We do this over and over until the user presses a key or begins to have seizures.

Scaling and rotation can be accomplished quite easily with the DRAW statement, although it involves some weird looking code. First, lets define a shape that we can scale and rotate.

Interpretation: "move up 5 spaces without drawing, draw 5 spaces left, draw 10 spaces down, draw 10 spaces right, draw 10 spaces up, draw 5 spaces left, and move 5 spaces down without drawing." This forms a box. Notice that I started at the center a nd not at a corner or side which would seem to be easier. Well, when you rotate something, it draws based on the starting point of the object, and we want it to rotate so if we put a pen at each corner of the box, it would draw a perfect circle. Therefo re we set the center of the box as the starting point of the object. I call this the "object handle," not to be confused with the handle used in the Windows API. The ta draw command stands for "turn angle," and obviously turns the object in the degrees you specify. So if we turned the box from 0 to 360 degrees, drawing the box at each step and erasing the previous image, we would get a rotating box. But we need one more function: VARPTR$ . VARPTR$ stands for "variable pointer," a term you can completely ignore unless you get into C or Assembly programming. We need to somehow get the box$ shape into the draw string command we use implement in the loop, so we have to take the address of the obje ct string and plug it into the draw string. This can be accomplished by using the X command, which tells VARPTR$ where to plug in the string's address so it can be used. With box$ defined above, here's the code for a rotating box:

Not that hard is it? We draw the box at the previous angle in black, and then draw the box at the current angle in blue.

Scaling is done pretty much the same way, but instead of changing the angle and erasing the previous image, we change the scale factor and erase the previous image. Recall that the default scale factor for the DRAW st atement is 4 pixels per unit. Well, if we increase this factor then we will have more pixels per unit, thus giving the image the effect of enlargement. So if we set up a FOR...NEXT loop which will increase the scale factor from 2 to, say, 2 00, we will get the effect of scaling. But lets start with a smaller image which is maybe 8 pixels wide from the start instead of 40 so we get a more dramatic effect.

Notice what we're doing here. We are starting the scale factor at one half of default (2) because the FOR...NEXT loop starts with s% at 2. The s draw command sets the scale factor. Notice also that we must continuously anchor the object handle at a point to keep it scaling about the handle. We do this by moving the object handle to 320,240 (center of screen) each time through the loop. Whenever we want to put a number into the draw string, we must concatenate the string format ( STR$ ) of the number within the string. Instead of concatenating the box$ with the rest of the string, it is faster to only pass the address of the substring with the VARPTR$ function.

So what if you want to scale and rotate something at the same time? Simple, just set up a FOR...NEXT loop which increases the scale factor as before, and within the loop increase the angle. But instead of subtracting a factor for the ang le to erase the previous angle, lets do it this way: erase the previous image with the current angle, increase the angle, then draw the current image with the new current angle. This way if we want to change the factor at which the angle increases, we wi ll only have to change one number instead of two

Try it out! Draw strings can get fairly complex, but you'll get used to them with practice and when you memorize the draw string commands.

The screen coordinates for different screen modes can be fairly difficult to work with, and they do tend to be weird numbers. To make your code simpler to write, you can define a logical plane over the physical plane. A n example of a physical plane is the 640x480 resolution established by the SCREEN 12 screen mode. You can define a logical, or alternate user-defined plane with the WINDOW statement.

This trivial example defines a logical plane which is 100x100. 50,50 is now the center of the screen, so this draws a red circle from the center with a radius of 10. The line statement draws a green line from the lower left corner to the center of the screen. Notice that defining a logical plane sets the origin (0,0) to the bottom left of the screen, instead of the default upper left. If you want the origin to be in the upper left with a logical plane, add the SCRE EN keyword after WINDOW . So to define the graphics mode 12 screen resolution, the code is:

Use whatever is more comfortable, but I would recommend using WINDOW SCREEN because there is less confusion when converting from logical to physical planes.

Finally , a little information on creating DRAW effects with the other QBasic graphics routines. Hope you know some trigonometry for this part. Recall that in the unit circle, which has a radius of 1, that the coordinates of a point on the circle given an angle is defined as ( COS(angle), SIN(angle) ) . Furthermore, if we are given a point on the circle, we can find the angle by drawing a vertical line perpendicular to the x axis from the point . If we take the arctangent of the vertical length of this line divided by the horizontal distance of this line from the origin, we will get the angle. So the angle is defined as ATN(Y/X) . With this knowledge, it would be possible to creat e a spinning line using only the line command. If we create a loop which increments the angle from 0 to 360 then we can take to COS,SIN of the angle to get the point we should draw to. But there's only one more problem. The QBasic functio ns COS and SIN think in radians, so we must first convert the angle to radians by multiplying PI / 180. That is quite easily done. Here is the code:

We start by initializing the graphics mode, then defining PI as a constant - a variable which will never change in the program execution. Then define the logical plane, and start the loop. The line starts from the center of the screen and goes to the coordinate specified by the COS,SIN of the angle. We loop until the user presses a key.

There is one more type of graphics that QBasic has a strong point for : text. Graphical effects can be made quite easily using only text in QBasic. There are a few functions that are quite useful when dealing with text. T he first is the CHR$ function. If you pass a number to the CHR$ function, it will return the ASCII (American standard code for information interchange) text value of that number. To find a listing of the ASCII character codes, look in the help contents, and there is a listing there. For example, to print a smiley face on the screen, the code is this:

Since the ASCII character code for a smiley face is 1, you can use the CHR$ function to get this. Another useful function is ASC, which returns the ASCII value of a text value you pass to it. So ASC("A") will return 65 because the ASCII value of A is 65. Every printable character (and then some) have an ASCII value, so these two functions make it quite easy.

Finally , the LOCATE statement is extremely useful for any text based program. LOCATE sets the text CP to the coordinates you specify. The first argument is the column, and the second is the row. So

Will print a solid white block at column 5, row 10. And that's it for graphics! You now know nearly every graphics routine in QBasic, and have the knowledge to make a game or highly graphical program. Graphics depend on how you arrange them, so it requires an artistic skill to some degree. If you get creative with these graphics commands, you can create nearly any effect you need.

It is not practical in real world terms to set up an application in one long list of code. Many early programming languages were purely linear, meaning that they started from one point on a list of code, and ended at another point. All of the code I have written in this tutorial so far has been purely linear. However, linear programming is not practical in a team environment. If one person could write one aspect of code, and another write another part of the progr am, things would be much more organized. QBasic contains the capability to meet these needs, called modular programming. You can break a program into different "modules" which are separate from the main program and yet can be accessed by any part of it. I highly recommend the use of separate modules in programming applications, although it is not a simple task to learn.

These separate modules are also known as procedures in the QBasic environment. There are two types of procedures: subs and functions. Subs merely execute a task and return to the main program, which functions execute a task and return a value to the main program. An example of a sub might be a procedure which displays a title screen on the screen, while a function may be a procedure that returns a degree in degrees given a number in radians. Function procedures are also used in Calculus, so you Calculus people should already be familiar with functions.

Procedures can accept arguments in what is called an argument list. Each argument in the argument list has a defined type, and an object of that type must be passed to the procedure when it is called. For example, the CHR$ QBasic functio n accepts a numeric argument. The function itself converts this numeric argument into a string representation of the ASCII value of the number passed, and returns this one character string.

Procedures in QBasic are given their own screen. When you enter the QBasic IDE, you are in the main procedure which can access all the others. Other procedures are created by typing the type of procedure ( SUB or FUNCTION ), t he procedure name, followed by the complete argument list. You can view your procedures through the VIEW menu. Here is an example of a sub procedure which performs some operations for a program that will be using graphics, random numbers, and a logical plane.

The only thing you need to type is SUB initProgram () , and the screen will be switched to that procedure. The END SUB is placed there for you, so the only thing you need to type then is the code within the sub. Try typing thi s out on your own to see how this works. This procedure is called by simply typing initProgram in the main procedure. An alternative method is CALL initProcedure () . Right here the parentheses are optional, but if you were to pass arguments to the procedure, parentheses would be required with the CALL statement. Now lets try passing an argument to a procedure. We will pass two arguments to a procedure called center which are a string containing the text to be c entered, and the horizontal location on the screen at which you wish to center it.

The first line after the sub declaration positions the starting point of the text at the horizontal location we passed at the second argument and vertical coordinate. The vertical coordinate is calculated by subtracting one half the screen's width in characters (41) and half the LENgth of the text we passed as the first argument. We would call center from the main procedure like this:

Or like this

It's quite simple actually. Functions are slightly different and involve an additional part which subs do not: a return value. The return value is specified by assigning the value you want to return to the function name from within the function defin ition. When calling the function from within the main procedure, the name of the function is treated as a value which is evaluated at compile-time. Here is an example of a function definition:

The function is implicitly called in this program

We treat the value returned from the function as a value we can immediately assign to another value. The variable radianValue! is given the value returned from convert.To.Radians . These concepts are supported in all programming languages , so this information will be beneficial to you in the future.

There is one final concept which has proven to be very successful in programming: a message loop. With QBasic, you can construct a loop which runs for the length of the program, receives input from the user, and executes a message based on what the us er does. We will construct a basic application which receives input from the user in the form of an arrow key, and moves a box on the screen based on the direction the user pressed. The arrow keys are different from nor mal inputted keys received with INKEY$ . On the enhanced 101 keyboards which have arrow keys, INKEY$ returns two values: the ASCII text representation of the key pressed, and the keyboard scan code of the key pressed. Since the arrow keys do not have an ASCII text representation, we must use the keyboard scan codes for them. The keyboard scan codes can be viewed in the HELP | CONTENTS section of the QBasic menus. For this program, we will have two procedures in addition to the main procedure. The first will initialize the program settings and position the character in his starting position. The other will move the guy in the direction which we pass to the function. The main procedure will call the sub procedures and contain s the main message loop which retrieves input from the user. First of all, here is the code for the main procedure:

This code is fairly self explanatory with the exception of the SELECT CASE... END SELECT structure which I have not yet explained. This type of conditional testing format tests a condition, and several cases for that condition are then tested. In this case, we are seeing IF INKEY$ = CHR$(0) + CHR$(72) , IF INKEY$ = CHR$(0) + CHR$(80) , and so on. This is just a more legible format than IF...THEN...ELSE . Note that in the QuickBasic compiler, a CASE ELSE statement is required in the structure for what reason I have no idea. The above code is the driver for the rest of the program. First some CONSTants are declared which remain co nstant for the duration of the program and in any module. A user defined type is declared to store the coordinates of the character. Then an endless loop is executed, calling the appropriate procedure for the arrow key pressed until the user presses the space bar ( CHR$(32) ). Here is the code for the initScreen procedure:

The WIDTH 80,50 statement sets the screen text resolution to 80 columns and 50 rows. We then print a smiley face in the middle of the screen in a nice bright blue color. Next we need to write the move proc edure, and then we will be done with the program.

And that's the whole program... confusing as it may be! Ideas should be going through your head about what you could do with this information. Entire games can be created with this simple construct.

There are more things to consider, but they are beyond the scope of this tutorial. If you were to design an application in QBasic, you would only need the information from this section and one heck of an imagination. Programming takes k nowledge of the language and a creative mind... programs are made by programmers with both. If you can develop a creative mind, then you can develop any program conceivable.

If you've read this tutorial and understood the information within, you can honestly call yourself a QBasic programmer. That might not sound very prestigious, and you probably won't get a job in the real world by saying that, but ah well. QBasic is a fun and widespread language. But you might be wondering, what do I do now? My suggestion is to continue to learn another language. I would recommend Pascal if you are serious about programming because there are fundamental concepts that you still need to learn. There is also information which I have deliberately left out of this tutorial with the hope that I can teach you a style of programming which is becoming increasingly popular.

BASIC is an extremely popular language with thousands of different versions world-wide, so it is mandatory that you learn it. But if you will continue in programming, knowing a Mid-level DOS language will not suffice in the real world. I suggest learn ing some Pascal next, and then moving on to the world of Windows. When I say "learn" I do not mean memorize every command in the language, I mean "get familiar with the concepts." You may not learn how to do anything beyond what you can do in QBasic, bu t that's fine.

Loops
�����
����� ������������

logo

  MENU

Introduction to qbasic, control statement, branching statement, looping statement, library function, array in qbasic, modular programming, file handling, qbasic statements.

A command or set of instructions used in the program is called statement. The statement performs specific task in the program. There are several different types statements in QBASIC Programming language. For example, CLS statement clears the screen, PRINT statement displays output and INPUT statement takes the input from the users. In this section we will learn some general statements of QBASIC Programming.

This statement is used to clear the output screen. Generally it is used at the starting of the program.

Syntax : CLS

This statement is used to put comments in the program. It is non-executable statement. We can use (') instead of REM.

Syntax : REM

It is an an assignment statement which is used to assign value to a variable. LET is an optional statement.

Syntax : Let x = 5

It displays output on the screen. We can also use question mark (?) instead of PRINT statement.

Syntax : PRINT

             Or, 

              ?

The INPUT statement is used to accept data from the keyboard at the program execution time.

Syntax : INPUT ;

END statement is used to terminate the execution of the program. It stops the further processing of the program.

Syntax : END

7. READ .... DATA 

This statement can process large number of data, where LET and INPUT statement can process only one data at once. This statement read the given value of DATA statement and store them with suitable variable.

Syntax : READ , ,   ...

             DATA ,   , ...

Primary Logo

  • Principles of Management
  • Microeconomics
  • Computer and Information Technology Application
  • Macro Economics
  • Introductory Database
  • Human Resource Management
  • Financial Accounting
  • Business Communication
  • Business Finance
  • Management Information System
  • Business Statistics
  • Cost and Management Accounting
  • Business Law
  • Business Environment in Nepal
  • Fundamentals of Marketing
  • Basic Psychology
  • Sociology for Business
  • Basic Financial Management
  • Corporate Taxation in Nepal
  • Operations Management
  • International Business
  • Organizational Behaviour
  • Entrepreneurship
  • Business Research Methods
  • Nepalese Society and Politics
  • Business Ethics and Social Responsibilities
  • Financial Institutions and Market
  • Working Capital Management
  • Investment Analysis
  • Commercial Bank Operation
  • Productivity Management
  • Supply chain Management
  • Service Operations and Management
  • Management of Micro Enterprise
  • Micro Finance
  • Cooperative Management
  • Micro Insurance
  • Consumer Behavior
  • Marketing communications
  • Fundamentals of Selling
  • Services Marketing
  • financial Derivatives
  • Banking Law and Regulations
  • Treasury Management
  • Quality Management
  • Creativity and Innovation
  • Project Management
  • Industrial Relations
  • Business Plan For Micro Enterprise
  • Social Entrepreneurship
  • Entrepreneul Marketing
  • Retail Management
  • Distribution Management
  • Market Research
  • Public Relations and Media Management
  • Social Studies and Population Education
  • Compulsory Maths
  • Optional Maths
  • Health and Physical Education
  • Accountancy
  • Compulsary Maths
  • Environment, Population and Health
  • Social Studies
  • Compulsory Mathematics
  • Computer Science
  • Fundamentals of Nursing
  • Community Health Nursing I
  • Anatomy and Physiology
  • Basic Science Applied to Nursing
  • Medical and Surgical Nursing I (Theory)
  • Medical and Surgical Nursing II (Theory)
  • Geriatric Nursing (Theory)
  • Community Health Nursing II
  • Behavioral Science
  • Mental Health (Theory)
  • Child Health Nursing
  • Leadership and Management (Theory)
  • Midwifery I (Theory)
  • Midwifery II (Theory)
  • Midwifery III (Theory)
  • Gynecological Nursing
  • Nursing Council
  • Statements in QBASIC

Subject: Computer

  • Spreadsheet Software
  • Operating System
  • MS-DOS (Microsoft Disk Operating System)
  • Internal and External Commands Used in MS-DOS
  • Introduction to Windows
  • Word Processing Program: MS-Word
  • Application of Multimedia
  • Tools for Multimedia
  • Number system
  • Binary Arithmetic and Conversion
  • Application Software
  • System Software
  • Fundamental Knowledge of Computer
  • Mechanical Calculating Devices
  • Electro Mechanical Computers
  • Generation of Computer
  • Classification of Computer On the Basis of Work
  • Classification of Computer Based on Configuration
  • Computer Virus
  • Types of Computer Network
  • Network Architecture
  • Computer Networking
  • Network Topology
  • Terms Related to Network
  • Fundamental Knowledge of Computer Programming
  • Computer Ethics
  • Program Designing Tools
  • Computer Programming in QBASIC
  • Elements of QBASIC programming
  • Tools Used in Photoshop
  • Computer Graphics
  • Information and Communication Technology
  • Application of ICT
  • Web Page Designing
  • HTML and Its Introduction
  • Different Tags Used in HTML
  • Presentation Software (MS PowerPoint)

Coming Soon

Things to remember.

Image

Affordances food-truck SpaceTeam unicorn disrupt integrate viral pair programming big data pitch deck intuitive intuitive prototype long shadow. Responsive hacker intuitive driven

Prototype intuitive intuitive thought leader personas parallax paradigm long shadow engaging unicorn SpaceTeam fund ideate paradigm.

Kelly Dewitt

Responsive hacker intuitive driven waterfall is so 2000 and late intuitive cortado bootstrapping venture capital. Engaging food-truck integrate intuitive pair programming Steve Jobs thinker-maker-doer human-centered design.

Unicorn disrupt integrate viral pair programming big data pitch deck intuitive intuitive prototype long shadow. Responsive hacker intuitive driven

Leave A Comment :

  • A statement is a set of instructions written by using keywords or commands of QBASIC. 
  • LET is an assignment statement. It is used to assign the value to a variable.
  • The remarks may be useful in a program to explain about different kinds of statements and user defined words.
  • PRINT statement provides output on the screen. 
  • The CLS statement clears the screen.
  • It includes every relationship which established among the people.
  • There can be more than one community in a society. Community smaller than society.
  • It is a network of social relationships which cannot see or touched.
  • common interests and common objectives are not necessary for society.

© 2021 Saralmind. All Rights Reserved.

Remember Me

Doesn't have an account ? Click Here

assignment statement in qbasic

Forgot Password

Already have an account ? Click Here

REGISTER NOW

Already have an account ? Click Here To Login

I agree with Terms and Privacy

QBasic/Full Book View

  • 1.1 6INPUT.BAS
  • 1.2 INPUT # and LINE INPUT
  • 2.1 Your first QBasic program: 1HELLO.BAS
  • 2.2 1HELLO.BAS
  • 2.4 2HELLO.BAS
  • 2.5 PRINT, Commas, Semicolons, tab (n) and CLS
  • 2.6 3HELLO.BAS
  • 2.7 Variables
  • 2.8 4FACE.BAS
  • 2.9 LOCATE statement
  • 2.10 5FACE.BAS
  • 2.11 COLOR statement
  • 2.12 Color by Number
  • 2.14 Summary
  • 3.1 Equation Setup
  • 3.2 7MATH.BAS
  • 3.3 Understanding 7MATH.BAS
  • 3.4 8MATH.BAS
  • 3.5 Understanding 8MATH.BAS
  • 3.6 9TIP.BAS
  • 3.7 Tip Calculator
  • 3.8 10OROP.BAS
  • 3.9 Parentheses and Order of Operations
  • 3.10 Random Numbers
  • 3.11 11RND.BAS
  • 3.12 More on RND
  • 4.1 Conditional execution
  • 4.2 True or False
  • 4.4 IF...THEN...ELSE
  • 4.5 13 ELSEIF
  • 4.6 FOR...NEXT
  • 4.7 14FOR.BAS
  • 4.8 WHILE...WEND
  • 4.9 15WHILE.BAS
  • 4.10 DO...LOOP
  • 4.11 12IF.BAS
  • 4.12 SELECT CASE
  • 5.2 The keyboard buffer
  • 5.3 Scancodes
  • 6.1 Purpose
  • 6.2 Procedure vs. Function
  • 6.3 GOTO and GOSUB
  • 6.4 ON ERROR
  • 6.5 Declaring a subprocedure
  • 6.6 Declaring a function
  • 7.1 Built-in Types
  • 7.2 User-defined type
  • 7.4 Multidimensional array
  • 7.5 Non-zero base
  • 8.1 The OPEN statement
  • 8.2 Input and output
  • 8.3 Reading the file from disk
  • 8.4.1 Part 2: New file
  • 9.1 Cursor manipulation
  • 9.3 Formatted printing
  • 9.4 Text animation
  • 10.2.1 Syntax
  • 10.2.2 Example
  • 10.4 Simple Musical Keyboard In Qbasic
  • 11.1 What QBasic can do with Graphics
  • 11.2.1 PSET
  • 11.2.2 LINE
  • 11.2.3 CIRCLE
  • 11.2.4 PAINT
  • 11.2.5 DRAW
  • 11.3 Making An Image Using the DATA command
  • 12.1.1 Basic Movement
  • 12.1.2.1 WARNING
  • 12.1.3.1 Tip
  • 13.1 Simple 3D Box
  • 14.1 WARNING
  • 14.2 Simple image
  • 14.3 Secondary use of _newimage for setting screen details
  • 15.1 Websites
  • 15.2 Further in programming
  • 16.1 Calculator
  • 16.2 Basic Game
  • 16.4 Binary Coder
  • 16.5 Projectile Game
  • 16.6 Check hearing
  • 17.1.1 ABS()
  • 17.1.2 ACCESS
  • 17.1.3 ASC("C")
  • 17.1.4 ATN()
  • 17.1.5 BEEP
  • 17.1.6 BLOAD
  • 17.1.7 BSAVE
  • 17.1.8 CALL ABSOLUTE
  • 17.1.9 CASE
  • 17.1.10 CHAIN
  • 17.1.11 CHDIR
  • 17.1.12 CHR$()
  • 17.1.13 CINT()
  • 17.1.14 CIRCLE
  • 17.1.15 CLEAR
  • 17.1.16 CLOSE
  • 17.1.17 CLS
  • 17.1.18 COLOR
  • 17.1.19 COMMON
  • 17.1.20 CONST
  • 17.1.21 DATA
  • 17.1.22 DATE$
  • 17.1.23 DEF SEG
  • 17.1.24 DEST(Only QB64!)
  • 17.1.25 DIM
  • 17.1.26 DO .. LOOP
  • 17.1.27 DRAW
  • 17.1.28 END
  • 17.1.29 END TYPE / END DEF / END SUB / END FUNCTION / END IF / END SELECT
  • 17.1.30 ENVIRON
  • 17.1.31 EOF()
  • 17.1.32 ERASE
  • 17.1.33 ERROR
  • 17.1.34 EXIT
  • 17.1.35 FOR .. NEXT
  • 17.1.36 GOSUB
  • 17.1.38 INCLUDE (QUICKbasic Only)
  • 17.1.39 INKEY$
  • 17.1.40 INPUT
  • 17.1.41 INPUT #
  • 17.1.42 INSTR
  • 17.1.43 LEFT$()
  • 17.1.44 LET
  • 17.1.45 LINE
  • 17.1.46 LINE INPUT #
  • 17.1.47 LOADIMAGE (QB64 Only)
  • 17.1.48 LOOP
  • 17.1.49 LPRINT
  • 17.1.50 MID$
  • 17.1.51 MOD
  • 17.1.52 NEWIMAGE(Only QB64!)
  • 17.1.53 OPEN
  • 17.1.54 PALETTE
  • 17.1.55 RANDOMIZE
  • 17.1.56 READ
  • 17.1.57 REM or '
  • 17.1.58 RETURN
  • 17.1.59 RND
  • 17.1.60 PLAY
  • 17.1.61 PRINT
  • 17.1.62 PSET
  • 17.1.63 SCREEN
  • 17.1.64 SEEK
  • 17.1.65 SGN
  • 17.1.66 SHELL
  • 17.1.67 SLEEP
  • 17.1.68 SOUND
  • 17.1.69 STR$
  • 17.1.70 SYSTEM
  • 17.1.71 THEN
  • 17.1.73 USING
  • 17.1.74 VAL()
  • 17.1.75 WHILE ... WEND
  • 17.2 ASCII Chart

Basic Input

The INPUT command is used to gather input from the user. This section will attempt to teach you how to gather input upon request from the user. For real-time input, see QBasic/Advanced Input .

Here is the syntax of the input command:

When a semicolon (;) is used after the text output to the user, a question mark (?) and space ( ) are added to the output. When a comma (,) is used, no question mark is added.

If a string is specified (e.g., 'name$'), anything the user enters before pressing the 'return' key will be accepted.

If a numeric variable (e.g., 'age') is specified, the user must enter a number. If any non-numeric key is entered, the error message "Redo from start" will be output and the INPUT command rerun.

Please note: In the PRINT command, the (;) function concatenates (joins) the contents of the string variables with the text between the quotes (" "). Note the use of spaces so that the final printed text reads properly.

If a numerical variable is specified within the PRINT command, additional space is automatically added both before and after the number.

See also: LINE INPUT command to read a line of text from a file (and place the result in a string variable) or to input a series of variables (in which case any comma found will be treated as a delimiter between fields).

INPUT # and LINE INPUT

INPUT # uses an open file stream to collect data from the file itself. The file may be a data file, a bitmap, or a text file. The syntax is:

LINE INPUT is used to collect an entire line of a text file. Syntax:

WARNING: If input is taken beyond the file end, the error : "Input past end of file " is issued. You can use LOF and EOF functions to prevent errors. (LOF stands for LENGTH OF FILE while EOF stands for END OF FILE)

Text Output

Your first qbasic program: 1hello.bas.

The following paragraph requires a computer with QBasic installed

To begin, write down everything from the program below ("PRINT "Hello World") into a text editor or into the QBasic IDE (Integrated Development Interface) itself and save it as "1HELLO.BAS". Next open the file in QBasic (unless you used QBasic IDE in which case it is already open) and press F5. Optionally you can use the "RUN" menu located on the menu bar at the top of the IDE window. This will execute (run) the program. The words "Hello World" should appear on the upper left hand side of the screen. You have just executed your first QBasic program. If you press F5 again, another line of text saying "Hello World" will appear on the upper left hand side of the screen pushing the first one down to the second row of the screen. You can follow the same procedure for the rest of the example programs in this wikibook.

PRINT is QBasic's text output function. It is the command that we will be exploring through this section. PRINT is a QBasic function that requires arguments. The argument in the "Hello, World!" program we just ran were the words "Hello, World!". So, PRINT is the function and "Hello, World!" is the argument we pass to the function.

PRINT [Text to screen]

Note: For a short cut, just use a question mark "?" in place of the command "PRINT". Likewise you can use a single quote "'" in place of the key word REM to insert comments in your code

PRINT, Commas, Semicolons, tab (n) and CLS

This is what the program output should look like:

The first line of 2HELLO.BAS outputs "This line will be erased." to the screen. However, in the second line, the CLS command clears the screen immediately after. So, it will only flash momentarily. The text "Hello Jupiter" should line up with '2' under it. More than one comma can be used consecutively. In this example, after "Good Bye" two commas are used to move "For Now" over two tab columns. "For Now" should line up with '3'.

My final statement on this topic is to play around with it. Try using commas and semicolons in a program.

Variables are used to store information. They are like containers. You can put information in them and later change the information to something else. In this first example they may not seem very useful but in the next section (Input) they will become very useful.

In this example we use two types of variables: string variables and numeric variables. A string variable holds a string of characters, such as words. (A character is a letter, digit or symbol.) In this case, the characters are letters. A string variable is denoted by ending the name of the variable with a dollar sign. The string variable in this program is hello$ . Whatever value you assign to hello$ will be displayed in the PRINT statement. The numeric variable is number . Numeric variables do not have a special ending like string variables.

LOCATE statement

LOCATE allows you to position the cursor for the next piece of text output. Contrary to Cartesian coordinates which read (X,Y), the locate statement is LOCATE Y,X. In this case Y is the distance down from the top of the screen and X is the distance from the left side of the screen. The reason that LOCATE does not follow the standard coordinate system is that it is not necessary to include the X portion; you can use the format LOCATE Y which just specifies the line to start on.

LOCATE[row, column] LOCATE[row]

COLOR statement

The program 5FACE.BAS is broken into many sections to make it easier to read. This is an example of a good programming habit. Each three-line piece of code specifies what the color, location and form of its part of the face. The order of the position and the color is unimportant. The new statement COLOR allows you to change the color of the text. Once changed, all output will be in the new color until COLOR or CLS is used.

COLOR [foreground] COLOR [foreground], [background]

The colors are designated by numbers which will be discussed in the next section.

Color by Number

There are 16 colors (in screen mode 0), numbered from 0 to 15.

0 Black 8 Gray
1 Blue 9 Light Blue
2 Green 10 Light Green
3 Cyan 11 Light Cyan
4 Red 12 Light Red
5 Purple 13 Light Purple
6 Brown/Orange 14 Yellow (Light Orange)
7 Light Grey (White) 15 White (Light White)

If you look carefully at this chart you can see that there are 8 main colors (0 through 7) and then those colors repeat, each in a lighter shade. You may also notice that the colors act as a combination of binary values (where blue=1, green=2, red=4, etc.) This makes it much easier to memorize the color scheme. Blinking colors are also available: at 16, the colors start over again with blinking black and extend through 31 (blinking white). However, the blinking option is not available for the background, only for the text (foreground). Add 16 to the color you wish to blink. e.g.: 2+16=18 - Blinking Green, 4+16=20 - Blinking Red.

It is possible to switch the blinking foreground text with an intense background, but this task is beyond the scope of this QBasic textbook, and may not work when MS Windows displays the console in a windowed mode.

On a VGA compatible video card, you can inspect and change the font used in screen mode 0.

You can now use PEEK and POKE to access the character data. It starts at absolute address &HA0000 and every character is 32 bytes, each of which is a row of eight bits. The highest bit of each byte corresponds to the leftmost pixel of each row. Usually only the first 16 or 8 rows are used, depending on the WIDTH setting.

When you're done, it's important to put the memory mapping back to what QBasic expects:

In this section we looked at several methods to manipulate text output. All centered around the PRINT statement. LOCATE and COLOR modified where the text was displayed and how it looked. We used CLS to clear the screen and gave a brief introduction to variables which will be expanded upon in later sections.

There are six numerical variables within QBasic:

Type Minimum Maximum
Integer -32,768 32,767
Long Integer -2,147,483,648 2,147,483,647
Float -3.37x10^38 3.37x10^38
Double -1.67x10^308 1.67x10^308
64-bit Integer -9,223,372,036,854,775,808 9,223,372,036,854,775,807
64-bit Float ±1.18E−4932 ±1.18E+4932

Please note that Integer and Float type variables for 64-bit are available only in QB64.

A lot of programming is math. Don't let this scare you: a lot of the math is simple, but it's still math. In this section, we will look at doing some basic math (the same stuff you learned in the 3rd grade) and manipulating numbers.

Equation Setup

In QBasic an equation has a basic setup a right side and a left side. For instance X=5, as you can probably figure out, this sets the variable X to 5. But we can use variables on the right side too. Y=X*10 would set Y equal to 10 times X, in this situation, 50. In this next program I will show several equations to give you a feel for math.

Understanding 7MATH.BAS

The most important thing you can take away from this is the setup for math equations. I think you can figure out what all the symbols are and what they do, but QBasic is picky about equations. For 'e=a+b', if you try 'a+b=e' it will not work. The final thing I would like to address in 7MATH.BAS is the INT() function. As far as vocabulary, a function is something that takes in a piece of information and gives you another piece of information back. So PRINT, was a statement, and INT() is a function. The INT() function takes a number and truncates its decimal, it does not round. So INT(5.1) is 5 and INT(5.999) is still 5. If you want to round a number use CINT().

Understanding 8MATH.BAS

8MATH.BAS shows one simple concept that is very important in programming, but impossible in math. The way that the computer calculates the equation is it does all the math on the right side of the equation and then sticks it in the variable on the left side. So the equation x=x+5 makes perfect sense, unlike math where it is a contradiction. Reassigning a value to a variable based on its current value is common and a good way to keep the number of variables down.

Tip Calculator

9TIP.BAS calculates your tip and total bill from the bill and percent tip you wish to give. The first three lines clear the screen and get the information from the user. The fifth line changes the tip from a percent to the correct decimal by dividing by 100 (ex. 20%=.2 because 20/100=.2) the next line takes that percent and turns it into a dollar value by multiplying the decimal value by the bill. So if your bill is $20.00 and you leave a 20% tip, it multiplies 20*.2 which is 4 or $4.00. The last three lines format the output. This is a good example of a complete program. It collects information from the user, it processes the information and it gives the user feedback. Also, the middle section of the program is a good example of variable conservation. This is subject that will take some practice to get used to. In writing a program, if you use too many variables, it will become difficult to keep track of all of them. If you try and conserve too much, you code may become difficult to understand.

You may notice that the program may print more than two decimal places if you enter a bill that is not an exact dollar value. As an exercise, try modifying the program so that it only displays two decimal places - you can use the CINT() function or any other rounding method you intend to use.

Parentheses and Order of Operations

10OROP.BAS is an example of order of operations and how parentheses can be used to manipulate it. I do not want to go into an indepth explanation of the order of operations here. The best advice I can give is unless you are sure of the order of operations, use parentheses to make sure the equation works how you want. All you need to know about parentheses is that the deepest nested parentheses calculate first. If you wish to know more, there are plenty of algebra resources available. On that note, you may wish to brush up on algebra. While it is not necessary for programming, it can help make programming easier and it can allow you to create more advanced programs.

Random Numbers

Though we will not go into their use until the next section, I would like to discuss the generation of random numbers. QBasic has a random number statement, RND, that generates a random decimal between 0 and 1. You can think of it as a random percent. At first, this may seem like an odd way to generate random numbers. However, with a little math it is very easy to manipulate this to provide numbers in whatever range you want. The first step is to multiply RND by a number (the range you want). For instance 'RND*10'. This will return random numbers (decimal numbers) between 0 and 10(both included). So, to pick a random number between zero and ten we would say '(RND*10)'

More on RND

A few notes on 11RND.BAS, the second line, RANDOMIZE TIMER, sets it so that the computer uses the current time to pick random number. If you don't do this, it picks the same random number every time (try it, write a one line program, PRINT RND, and run it over and over, your screen will fill up with the same number) this can prove useful for some applications, but not most. Stick RANDOMIZE TIMER in at the top of all your programs that use the RND statement and they will be far less predictable. This program just show some ways to choose what you want from your random number generator. The last line shows that you can be very specific in what you get. Make sure to run this program several times to see the different results.

Flow Control

Conditional execution.

To choose between two or more sections of the program to execute, the IF statement can be used. It is also possible to use the WHILE, DO UNTIL and CASE statements. All of these control conditional execution by using a Boolean logic 'test', the result of which is either TRUE or FALSE. To repeat a section of code for a set number of times, the FOR statement is used.

The IF test can be executed in a single line, however it can also be used like the others to control a block of code.

True or False

Boolean logic is a test that yields one of only two possible results, true or false. The tests are always mathematical in nature .. when two characters (or strings) are 'compared' it is their ASCII codes that are used (thus a < b and b < A).

The comparison operators used in qbasic are: = true if two variables are equal < true if the first is less than the second =< true if the first is less than or equal to the second > true if the first is greater than the second >= true if the first is greater than or equal to the second <> true if the two are unequal

Multiple tests can be linked together in the comparison, using the 'AND', 'OR' and 'NOT' operators. We will cover exactly what these mean later on, but you probably understand the first two already.

One of the most useful statements in QBasic is the IF statement. It allows you to choose what your program will do depending on the conditions you give it. The next few programs will be taking a look at ways to use the IF statement.

The single line IF is the simplest example. To execute a block of code, the END IF is used

IF...THEN...ELSE

To choose between two different code blocks, the ELSE statement is used.

As an alternative to starting an entirely new IF THEN ELSE statement sequence. You can follow the THEN statement(s) with ELSEIF [conditional] THEN. This does not create a new level of nesting.

IF [conditional] THEN

ELSEIF [conditional] THEN

<increment> may be + or - and is optional. If omitted the default is +1. The code contained within the FOR loop will always be executed at least once because it is only at the 'NEXT' statement that the value of the variable is checked against the end value.

When the NEXT statement executes, the variable is modified by STEP value and compared against the end value. If the variable has not yet exceeded the end value, control is returned to the line following the FOR.

You can exit a FOR loop early with the EXIT FOR command.

WHILE...WEND

If the condition is true, the code following the WHILE is executed. When the WEND command is executed, it returns control to the WHILE statement (where the condition is tested again). When the condition evaluates to FALSE, control is passed to the statement following the WEND.

15WHILE.BAS

In the example above, you see a press any key prompt that waits until the user presses a key. (The INKEY$ feature will be described under Advanced Input .)

The DO...LOOP construct is a more advanced of the WHILE loop - as with other flow control blocks, it is marked by DO and LOOP to denote the boundaries.

It relies on a conditional statement placed after either DO or LOOP:

As an alternative, you can instead replace WHILE with UNTIL have the loop continue until a specific condition is met:

In some versions of BASIC the UNTIL or WHILE condition can follow the DO statement rather than the LOOP statement (pre-test) as apposed to the above shown (post-test).

SELECT CASE

The select statement is a substitute for repeated use of IF statements. The <variable expression> is evaluated and compared against each CASE <value> in turn. When a CASE <value> is found to match, the [do this] code following is executed. If an EXIT CASE is executed, control passes to the line following the END SELECT, otherwise the next CASE <value> is checked. If no matches are found, the CASE ELSE is executed. Note that <value> may be a number, character or string or logical expression (eg '>0', '<>1'). Note also that multiple CASE matches may be found and executed (so, for example, if two CASE <values> are 'CASE >1' and 'CASE >10', a <variable expression> that evaluates to 11 (or more) will result in both CASE >1 and CASE >10 being executed)

If a parameter would be covered by more than one case statement, the first option will take priority.

Advanced Input

Getting real time information from the user is a little more difficult. To do so, we will use the INKEY$ command, which checks to see whether a user typed a key and provides the keypress to the program.

Look at this code and then we will look at it in depth:

The first part is the DO-LOOP which constantly polls INKEY$ for a return value. In the basic use, INKEY$ returns an empty string if no keys are being pressed and continues with the program. Once a key is pressed, INKEY$ will return that key immediately.

The keyboard buffer

What is INKEY$ doing and how does it work?

While the INKEY$ command looks like it returns the key currently being pressed, this is not the case. It is used by the program to answer the question, "What is IN the KEYboard buffer?" To understand this you will need to understand what a basic buffer is and why it is used.

In older systems (not necessarily the IBM PC) a single chip processed keyboard input, and controlled the LED lights for caps lock and number lock. Because a computer does many things at once (e.g., take input from the mouse, crunch numbers, call subroutines, display new information on the screen), it needs to be able to remember what was pressed on the keyboard while it is busy. This chip contained some memory (called a buffer) that allow keeping track of a limited number of keypresses.

Within the Dos platform under IBM PCs, the hardware has changed slightly. Instead of a hardware buffer, pressing or releasing a key will interrupt the running program to add a keystroke to a software buffer located in the BIOS. This procedure is usually unnoticed by the user and has minimal impact on system performance. However, this buffer allows for 15 characters: attempting to overflow it when the computer is busy will cause a short beep and drop any further characters.

The INKEY$ command uses this buffer as a FIFO (First In First Out) buffer. As an example let's say you have a game that has a bouncing ball on the screen and a paddle at the bottom. The computer program constantly has to update the screen to show the movement of the ball. While it does this the program passes by an INKEY$ command to see what value is returned. If the user has pressed a key since the last time the command was invoked it will return that key. Let's say the ball is moving over to the right and the user needs to press the "R" key to tell the program to move the paddle right. Since the program is busy moving the ball and updating the screen, it does not instantaneously notice that the user has pressed the key. Instead, the key press is stored in the keyboard buffer, and retrieved a few milliseconds (or microseconds) later when the INKEY$ command is used.

In many programs (as above), INKEY$ will appear nested in a loop. It is requested over and over again. This allows the program to get user input one character at a time. Using our example above, the user may need to press R over and over again until the paddle is under the ball. On the other hand, the user may press R too many times and need to press L to move it left. Because the INKEY$ command is using a FIFO buffer it will always retrieve the keys pressed in the same order as they were typed.

In summary, the INKEY$ command will always return and remove the first character in the keyboard buffer. Generally speaking, it is used over and over to retrieve every key that has been pressed, and to allow a user to interact with a program in a close approximation to "real time." If there is no key in the keyboard buffer, INKEY$ returns an empty string (no character).

Some keypresses are not associated with an ASCII character. When one of these keys is pressed, INKEY$ returns a string with two characters: the first character is a null (ASCII code 0), and the second is the raw scan code for the keyboard. A full listing of the scancodes can be found within the QBASIC help file. You can also determine the scan codes by examining the results of INKEY$ as you press those keys in question.


Some keys cannot be directly detected by INKEY$.

Subroutines and Functions

Subroutines and functions are ways to break up your code into reusable 'lumps'. They allow the programmer reuse a large set of common instructions just by calling the appropriate procedure or function.

For example, lets say you need to PRINT multiple Tables of values. One way to do this is to just enter all the Table PRINT commands directly into where you need them. However this not only makes the program very large but also makes it harder to debug or change the 'style' of the table. A simpler way is to create a single 'Print Table' procedure and enter all of the PRINT commands there. Then, each time you need to print a Table, you would simply 'call' the 'Print Table' procedure with a list of the values to be printed.

Procedure vs. Function

A procedure does something and does not return anything for the programmer. For example, a procedure might be used to set the screen mode and palette.

A function does something and RETURNS a value. For example, if you need to find the average of two values, you might write a function that takes in two numbers and returns the average.

GOTO and GOSUB

The GOTO and GOSUB statements were the original methods by which subroutines were created. They were most common on older basic implementations and are kept around for compatibility reasons; however, their use is not recommended in other programming languages or in large scale projects, both because GOTO's make it harder to 'follow' the program flow and because GOSUB's do not 'isolate' the changes made to any variables.

These two commands depend on Labels, which come in one of two forms. The first and older form involves writing line numbers at the beginning of each line (usually in increments of 10). The newer method looks similar to other programming languages, which is a single word followed by a colon.

The GOTO statement is simple; it just moves the execution point to a given Label:

The GOSUB statement transfers control to a given Label, however when a RETURN statement is encountered, execution returns to the line following the GOSUB statement. Any changes made within the GOSUB will be to actual variables used within the 'main' code.

The ON ERROR allows you to define an error handler for your program; when an error occurs, it immediately jumps to the given label. The control returns once the program reaches a RESUME statement, which can either return control to the same point, the next statement, or any other desired label.

Within Qbasic, the error handler cannot be located within any subroutines. As such, any error checking or flags will have to be handled through the use of variables that are shared with the main module.


While the QBasic documentation states ON ERROR RESUME NEXT is a valid statement, this is incorrect.

NOTE: If your error handling routine does not have a "resume" statement in it (IOW you try to do it all with gotos) error handling will only work once - the next "on error" will be ignored and the program ends as if you had no "on error" statement at all. This problem does not seem to be mentioned in any of the documentation. It took me three hours to figure out why two nearly identical program portions acted so differently.

Declaring a subprocedure

A superior method of declaring a subprocedure is using the SUB statement block, because (by default) any new variables used within the subprocedure are discarded on exit.

Under the QBasic IDE, doing so moves the SUB block to its own window to prevent accidental deletion of the module, and allows the easier organization of the program code.

Calling a subprocedure is as simple as writing the name of the subprocedure (passing any required parameters). If you want, you can use the CALL statement to indicate to other programmers that it is a subprocedure.

Whilst the Parameters passed into subprocedures are passed by 'reference' (i.e. they take on a new name within the SUB), any changes that are made to the values are 'reflected back' into the originals. By default, all other variables used within the SUB are discarded when the END SUB is reached (or an EXIT SUB is executed), except as below :-

To 'preserve' the values of variables used within the SUB for re-use on the next CALL, use the STATIC keyword at the end.

If you need access to a variable (that has not been passed as a parameter), use the SHARED keyword to define each at the start of the subprocedure (a SHARED variable retains its name).

Declaring a function

A function is a form of subroutine that returns a value. Everything that applies in defining a subroutine also applies to a function. Within the function, the return value is created by using the function name as a variable - the return value is then passed to the calling expression when a valid exit or end call is reached. There are two ways to return from a function, one way is to reach the END FUNCTION statement, the other is to make a call to EXIT FUNCTION. The difference between END FUNCTION and EXIT FUNCTION is that there can only be a single END FUNCTION and it must appear after all other code for the function as it denotes the end of a code block. EXIT FUNCTION can occur multiple times and can be placed anywhere deemed appropriate.

Functions are declared in the same way as variables - it returns the variable type it's defined to return, in the same way variables are defined to contain their specified type. By default, it is a number, but appending a dollar sign indicates that it is returning a string.

Functions can only be called within an expression; unlike subroutines, they are not a standalone statement.

Arrays and Types

Built-in types.

QBasic has five built-in types: INTEGER (%), LONG(&) integer, SINGLE(!) float, DOUBLE(#) float and STRING($). QB64 has two more built-in types: _INTEGER64 (&&) and _FLOAT (##)

Implicit declaration is by adding the type character to the end of the variable name (%, &, !, #, $, &&, ##). See QBasic/Basic math for more.

Explict declaration is by using the DIM statement before first use:

If you do not use either implicit or explicit declaration, QBASIC interpreter assumes SINGLE type.

User-defined type

A user defined type allows you to create your own data structures. Please note that custom types are similar to arrays.

You can then declare variables under this type, and access them:

This above example shows how a custom type can be used for maintaining data, say on a player who plays a game.

An array is a collection of values stored in a single variable. A STRING is an array of characters (so, for example, char$(1) means 1st character in string char$). Arrays of numbers should be defined using the DIM instruction (unless you DIM them, they are limited to 10 elements on each dimension).

By default, arrays in QBasic are static in size and cannot be changed later in the program. Code that will set up this type of array is as follows:

TYPE can be any of the built in QBasic (INTEGER, LONG, SINGLE, DOUBLE, STRING) or user-defined type. If this is not specified, the array takes the Type defined by the variable name suffix - INTEGER (%), LONG(&) integer, SINGLE(!) float, DOUBLE(#), STRING($) - or INTEGER if none.

WARNING: If your data Type is string, DIM string(10) defines a SINGLE string of 10 characters, NOT 10 strings of arbitary length ! (10 strings of up to 128 chars each would be defined as DIM string(10,128)

By issuing the Meta Command '$DYNAMIC at the beginning of your program you can cause your arrays to be dynamic:

This is now perfectly legal code.

To free up space occupied by an array, use the ERASE statement.

Multidimensional array

An array isn't restricted to one dimension - it's possible to declare an array to accept two parameters in order to represent a grid of values.

You cannot use the REDIM statement to change the number of dimensions on the array, even with dynamic allocation.

Non-zero base

In most languages, arrays start at the value 0, and count up. In basic, it's possible to index arrays so that they start at any value, and finish at any other value.

You can change the default lower bound with the OPTION BASE statement.

In this lesson, we will learn how to create and modify files. In doing so, we will create a portion of a text editor to handle reading and writing files to and from disk - the program won't be complete by the end of this chapter, but will be finished within Advanced Text Output.

Let's start by setting up out main procedure:

As you can see, we are using CASE rather than IF . IF statements can sometimes work better than case statements, but for now, we want to avoid spaghetti code (where there are too many GOTO 's).

So far, we don't really have much, but it's a start. We've asked the user what they want to do, and finished 1/3 options. Not so shabby when you put it that way!

The OPEN statement

The open statement allows either reading or writing information from the disk. In general, the open statement follows this pattern:

The file$ determines the filename to use. The FOR portion indicates how the file will be accessed or operated - it may be APPEND, BINARY, INPUT, OUTPUT, and RANDOM. The AS # is the identifier used for the file handle in question - this may be a variable if desired.


If you allow the user to enter a filename that does not exist on disk, you need to implement error handling using to react to this situation.

Input and output

When you need to access or write content to a file handle, the PRINT and INPUT statements expect a file handle to appear as the first parameter:

In some cases, you need to detect if you are going to reach the end of file - this is performed by the EOF function, which accepts a filehandle that takes input.

Reading the file from disk

We will now add a subroutine to read the complete file from disk, as lines of text, into an string array called text(). It is also possible to read a data file full of numerical values (and input these into a number array), however that is a different topic.

Note the code that finds the file 'size', by reading lines one at a time until the End Of File is reached, and the use of 'SEEK' to 'rewind' to the beginning again.

The example above treats the file as type=text. If the file contains numbers (for example, a data array of N integers per line x M lines) these can be read (input #) one at a time, directly into a numeric array. Input will read the numbers one at a time, 'stopping' after each is input. Numbers can be separated by 'anything' (so lines of text will be skipped).

Writing a file to the disk

The function for writing a file to disk is easier:

Part 2: New file

In order to create a new file, you have to open it for OUTPUT, then close it. Example:

NOTE: If you accidently open an existing file, all of its contents will be overwritten!

Advanced Text Output

Cursor manipulation.

As you try to write your text editor, you may realize that you will need to place the cursor in a given location on the screen. This is performed using the LOCATE statement.


Printing any character in the bottom-right corner of the screen will cause the display to scroll.

To change the current printing color, use the COLOR statement.

This can be used for title or status bars at the bottom.

Formatted printing

The PRINT USING statement allows you to output strings or numbers in a specified format. With this statement, you can write numbers out to specified decimal places or perform advanced output.

The most common format specifiers would be # and . , which reserve space for digits and decimal points respectively. You may also use the underscore to ensure that a given character is printed literally.

Note: PRINT USING is unable to add leading zeros to a number. E.g., if you specify 3 digits (###), a two digit number will be output with leading spaces.

Text animation

You require some time before doing a certain procedure. It is generally better to make an animation during the process which shows that the program has not hanged, but is going on. Why make that out of very complicated graphics? Use this: <syntaxhighlight lang = QBasic> SUB TEXT_ANIM

END SUB </SOURCE> The program uses INKEY$ , which you have not learnt yet, and SLEEP and DO...LOOP , which also you have not learnt. For more information, refer to Flow Control and Appendix .

QBasic has three ways of making sounds.

  • BEEP command
  • SOUND command
  • PLAY command

Earlier used as PRINT CHR$(07) the now available BEEP command makes a beep noise. It is commonly used to attract attention, when some important message is being displayed.

The two commands , as can be seen by running this program on a computer, are exactly the same.

The SOUND command produces sound of a specific frequency for a specific duration from the PC Speaker. Only one sound can be played at a time. If multiple SOUND statements are issued sequentially, every statement after the first will not execute until after the previous one finishes.

  • f - Frequency in Hertz, ranges from 37 to 32767
  • d - Duration in ticks, ranges from 0 to 65535, there are 18.2 ticks per second

Plays a 100 hertz wave for 18.2 ticks, about 1 seconds.

The lowest frequency allowed by QBasic is 37 Hz, which is roughly a D in the 2nd octave. The highest frequency is 32 767 Hz, but this tone can not be heard, because the normal human hearing range ends at 20 000 Hz.

A secondary function of the SOUND command is to use it to control time in a program.

This program will print the numbers 1 to 10, with a 1 second delay between each number,and play a sound of 3200hz having interval of 1 second.(edited by FalcoN)

The PLAY command is for playing musical notes,octave. It can only play one note at a time.

More than that the play command can play a complex stored "song" This is accomplished through the use of a song string. For string command detail, see QBasic/Appendix#PLAY .

Simple Musical Keyboard In Qbasic

This code uses a select case command to check values of note$ . Ucase$ is used to maintain that there be no difference if Caps Lock is applied. The play command is used to play different notes. The other features of play have not been used here.

What QBasic can do with Graphics

QBasic is not graphically very capable but many good programs can be created with it. Commands like PSET, CIRCLE, LINE, etc., are used to draw graphics in QBasic. Good examples of graphical programs created using QBasic are SYMMETRIC ICON and SYMMETRIC FRACTALS .

Screen will let you set how it will be used. Text Graphics, both, and the Size of the surface you are working with. Screen 0 .. means Text Only. Screen 12 .. means 64 X 480 X 16 Colors & Text.

The PSET command lets the programmer display pixels on the screen. Before you type the command in, you must make sure that a SCREEN command is in. Look at this example:

This command will display one yellow pixel at the coordinates 1, 1. The coordinates are X and Y coordinates, like any other mathematical situation. So the PSET command has to have this layout to function properly:

Remember that X coordinates are those that go left to right on the screen and Y coordinates are those that go Up to Down on the screen.

This simple program displays a line:

Simple Line

This displays a circle at the coordinates. The layout of the function is as follows:

Remember to put a SCREEN command at the front.

To use PAINT, there must be a SCREEN command declared. The command has coordinates that tells QBasic where to start. The color number specifies the color to paint with, and the bordercolor tells the PAINT command that it should not paint further when it encounters a pixel of that color. In almost all cases, you will need to use the bordercolor parameter, simply because without it, PAINT will cover the entire screen.

Making An Image Using the DATA command

Graphics using this command can either be made by using a Graphics Editor or by using the DATA command Manually. The DATA command is a way of inputting information into QBasic and being read by the READ command. Remember that the DATA command cannot be used in subroutines or functions. Look at this example:

The FOR commands declare the amount of pixels there are to be read. On this particular program, there are pixels of 10 by 10 (100) so we put:

We have now declared the x and y planes. You can change these values if you want a smaller or bigger picture Bitmap. The READ command reads the DATA commands and declares the information gathered as z.

The PSET reads the planes and the DATA read and a bitmap.

It works like the first example on this page, except it is reading more than one pixels

Advanced Graphics

Basic movement.

Animation is basically graphics that changes over a fixed period of time. In this we will be using a do-loop .

Explanation:

  • We have switched from the default qbasic text-only screen to one which enables graphics.
  • We have called the sub which creates the animation.
  • We have begun the do-loop until. This enables the animation to run until the user ends it by pressing a key.
  • We have set an increment of the coordinates. This allows the box to be drawn on a new position rather than the same one. If it movement in only one direction was wished, we had to set the increment only in one variable.
  • We have drawn lines from each coordinate to another. Note that each time one coordinate remains fixed while the others change.(In this I refer to the two coordinate sets, the first starting and the ending one)
  • We have issued a sleep command . This stops execution for 2 seconds . Without this the do-loop will execute more quickly than we want , and the animation will be very short-lived.
  • By using RND for the variables, you can create a randomized ,unpredictable animation.

Mouse-Control

In this step, we will use the QB64 inbuilt _mousehide,_mousex,_mousey,_mouseinput and _mousebutton commands to control the mouse input.

  • Here the first function "_mousehide" prevents the default pointer mouse format to be displayed on the screen
  • Mouseinput function retrieves mouse information.
  • The next functions "_mousex" and "_mousey" hold the current x and y coordinates of the mouse.
  • The lines draw a basic trigger .
  • The "_mousebutton" function returns the value of the mouse button pressed, "1" signifies the left button being pressed.
  • If the mouse button event has taken place within a certain enclosed area, a message in the form of "message$" is issued. This can be used later on.
  • The procedure, if the previous condition has been fulfilled , goes to line label "action" where any commands to be executed may lie.
  • Else , the process loops , until a "loop until" condition has been met. It can also be something other than the one given above.

These graphics and animations can be used to create a complete game. Instead of the "Mouse" functions, you could use the "Inkey$" command to issue various scenarios and cases, each with a complete code to decide what happens next.

Instead of making games which do not contain any user information, you could use ".txt" files to store information. This information can be later retrieved to make a game with a complete "Career" option.

3d Graphics

Simple 3d box.

3 Dimension or 3D graphics in Qbasic is nothing , but including an additional 'z' axis and to extend the 2 dimensional structure along that axis. This can be achieved by drawing a box, or the structure you want , each time at a new x and y position. It is quite like animation, except, we do not erase the structure after it being drawn , and there is no need of any intermediate pause. You can better understand by looking at the 3d box program given below.

NONE of these functions work in IDEs other than QB64.

Simple image

So you were most probably expecting miles of code. And there you have it, all you need to display an image in QB64!

So, what does this astoundingly simple piece of code even do?

A step-by-step explanation:

  • We have DIMed our variable Image as a long value. This is because the image handle returned by the _loadimage function is a long value.
  • x and y are our variables. They hold the values we need to put as the resolution. Thus ,for a 8n00 x 900 image, x = 800 ,y = 900.
  • The image variable Image is next being put the handle values of the image "TEST.jpg". A healthy warning: Keep the image in the folder of the QB64 IDE. Or else, the function won't work!
  • Next, we have resized the screen to fit the image. The newimage function requires three parameters, the resolution parameters and the color mode parameters. Here we have used 32-bit color modes, you can also use 256-bit pallete color modes.
  • Lastly, we put the image using _putimage, which takes the Image variable (our image handle) as its parameter.

an example of images in qbasic

Secondary use of _newimage for setting screen details

Well, you must be thinking, all these commands must be used in this exact same order. Nah, that isn't the case. You can use _newimage solo, to set the screen details, like shown below:

assignment statement in qbasic

There are many good websites out there on the topic of QBasic. This is a list of the best sites:

Petes QBasic Site : This site is mostly aimed at people thinking about programming video games in QBasic.

The QBasic Page : This is a good site for getting source codes and programs for QBasic.

QBasic News : The most recent and up to date news on the QBasic community.

QBasic Programming for Kids : A good site for young people to start programming.

Qb64  : All you need to know about QB64.

Also, the QB64 IDE has an inbuilt help page, giving essential help when you don't know how to use a command. The only drawback is , it does not show any help unless you select the command and right click on it, and click on "HELP ON ...." which means, you atleast have to know the name of the command before you seek help on it.

Further in programming

If you are learning QBasic, chances are that you are still new to programming. It is a diverse world, explore it!

A list of extremely good programming languages to continue further:

Sample Programs

This program can be used to make a simple, functioning calculator, very simply.

For reference goto Basic Math

Uses animation to make a simple game.

For reference , goto Advanced Graphics

A clock which is quite like a digital clock,with no hands.Use draw to make them if you want.

This is a little logical combination of all the chapters you have read so far.

Binary Coder

Yes, this is YES a binary decoder, but a binary Coder. This takes any decimal system number and converts it to binary. Run this program to see for yourself.

Just the trouble is: the binary code is reversed. You might have guessed it by looking at the last PRINT statement. I still haven't figured out how to reverse it, so I guess you have to do it yourself. And , the WHILE loop has a print statement with the semicolon at the end. That is used to ensure that the next number comes after it, not on the next line.

Projectile Game

Remember Gorillas? Well, take out the graphics and what you get is this:

Huh? Ok, now the maths is complicated , but the formula is basically the same. Here, the projectile has to land between 30 coordinates out of the hit object, or else you lose. See Wikipedia:Projectile motion for more information on the maths part. Tip: Add graphics. It will be a big , fat piece of code, but the final product will be AMAZING!

Check hearing

Ok, now , how high a frequency sound can you hear? Test your hearing with this program:

Check this out!

Returns the 'absolute' value of the expression, turning a negative to a positive (e.g. -4 to 4)

This sets the access of a file that has been declared into the program. There are three settings that the programmer can set. These are:

FOR APPEND opens the file as a text file and sets the file pointer to the end of the file, thereby appending new output to the file. If omitted, FOR RANDOM is the default, which would open the file as a sequence of fixed-length records and set the file pointer to the start of the file. New data would overwrite existing data in the file without warning.

Prints the ASCII code number of the character found within the brackets. If the programmer put in a string into brackets, only the first character of the string will be shown.

Part of the inbuilt trigonometry functions. An expression that evaluates to a numeric vale is converted to it's Arc-Tangent.

The BIOS on the motherboard is instructed to emit a "Beep" sound from the PC 'speaker'. See also SOUND and PLAY.

An older, outdated alternative is to use : PRINT CHR$(07)

This was replaced later by the BEEP command.

Loads a file saved with BSAVE into memory.

  • file_path$ is the file location
  • memory_offset is an integer specifying the offset in memory to load the file to

The starting memory address is determined by the offset and the most recent call to the DEF SEG statement

Saves the contents of an area in memory to a file that can be loaded with BLOAD

  • memory_offset is an integer specifying the offset in memory to save
  • length the number of bytes to copy

CALL ABSOLUTE

Pushes the provided arguments, which must be INTEGER, from left to right on the stack and then does a far call to the assembly language routine located at address. The code segment to use is set using DEF SEG. Normally QBasic will push the address of arguments, but if an argument is preceded by BYVAL the value of the argument will be pushed.

Note that because QBasic pushes the arguments from left to right, if you provide three arguments for example the stack will look like this:

QBasic doesn't set BP to the stack frame of your machine language routine, but leaves it pointing to the stack frame of the calling QBasic procedure, which looks like this:

The offsets indicated with -/+???? will depend on the sizes and presence of variables, return value and arguments. For example, an INTEGER variable will take two bytes, but a LONG variable four. As one might expect considering how QBasic passes arguments, variables are stored in reverse order of declaration. Contrary to when calling a machine language routine, the arguments here will always be addresses. For arguments passed by value, space is allocated on the stack and the address of that space is passed to the procedure.

Executes the statements after the first CASE statement where a test matches expression. The tests can be of the following forms:

This is an example of a program with no CASE commands that assigns different paths to values:

This is what a program looks like with the CASE command:

This chains execution to another QBasic program. Values may be passed to the other program by using the COMMON statement before the CHAIN statement. Note that execution doesn't return to the first program unless the second program uses CHAIN to transfer execution back to the first.

This is used for setting the working directory, also known as the current directory. The directory name is declared exactly like in DOS and long file names aren't supported. For example:

Note that this doesn't change the current drive and every drive has its own working directory. You can set the current drive like this:

This returns the string character symbol of an ASCII code value.

Often used to 'load' characters into string variables when that character cannot be typed (e.g. the Esc key or the F{n} (Function Keys) or characters that would be 'recognised' and acted upon by the QBASIC interpreter. The following four characters cannot occur in a QBasic string literal:

  • 0 Null: all characters up to the end of the line will get deleted, including this one.
  • 10 Line Feed: signals the end of the line.
  • 13 Carriage Return: this character will get deleted.
  • 34 Quotation Mark: signals the end of the string literal.

Here is a list of some character codes :-

This rounds the contents of the brackets to the nearest integer.

Lets the programmer display a circle. Like all graphics commands, it must be used with the SCREEN command.

Resets all variables, strings, arrays and closes all files. The reset command on QBasic.

Closes all open files

Closes only the file opened as data stream 2. Other files remain open

Clears the active screen. Erases all text, graphics, resets the cursor to the upper left (1,1), and also applies the current background color (this has to be set using the COLOR command) to the whole screen.

This lets you change the colour of the text and background used when next 'printing' to the current output window. It can be done like this:

You have a choice of sixteen colours:

These values are the numbers that you put in the COLOR command.

Note Only screen modes 0, 7, 8, 9, 10 support a background color. To 're-paint' the whole screen in a background colour, use the CLS command.

Declares a variable as 'global', which allows its value to be accessed across multiple QBasic programs / scripts (see also the CHAIN command)

Each program that declares 'variablename' as COMMON will share the same value.

NOTE. All COMMON statements must appear at the start of the program (i.e. before any executable statements).

Fixes a variable so it can not be changed within the program.

For example :-

Assigns the value 3.14159265 to PI.

PI must be assigned a value before it is used to calculate PI2. Typically all CONST are declared at the beginning of a program.

Use in conjunction with the READ and RESTORE command. Mostly used in programs dealing with graphics, this command lets QBasic read a large number of constants. The READ command accesses the data while the RESTORE command "refreshes" the data, allowing it to be used again.

A system variable that always contains the current date as a string in mm-dd-yyyy format. Use it like this:

Sets the current segment address.

  • address is a segment address that can contain a value of 0 through 65535.

If address is omitted, DEF SEG resets the current segment address to the default data segment. DEF SEG is used by BLOAD, BSAVE, CALL ABSOLUTE, PEEK, and POKE

DEST(Only QB64!)

_DEST sets the current write-to page or image. _DEST image_handle sends the destination image to an image of handle stored in long variable image_handle. _DESt 0 sends the destination image to the current screen being used.

This is used to declare an array (early versions of QBasic required all variables to be defined, not just arrays greater than 10)

The Array name can be of any type (Integer, Double, String etc). If not declared, single precision floating point is assumed. Strings can be 'declared' using $ sign (Integers with the '%' sign). The QBASIC interpreter tolerates numeric arrays of up to 10 count without these needing to be declared.

NOTE Early versions of QBasic did not explicitly set the contents of an array to zero (see CLEAR command)

Create an integer array called table% containing 100x2 = 200 entries

Create a string array called form$ containing 5 strings

Create an array called quotient that contains 20 double precision numbers

Used to create a loop in the program. The [condition] is tested only after the [program] code is executed for the first time (see also WHILE). For example:

This does not work But the following does

Used to draw a straight line from the current 'cursor' position in the current colour. DRAW defines the direction (up, down etc.) and the length of the line (in pixels). For example:-

The letter in front of each number is the direction:

The drawing 'cursor' is left at the position where the line ends. u50 draws from 50,50 upwards ending at 50,0 r50 draws from 50,0 to the right, ending at 100,0 d50 draws from 100,0 downwards, ending at 100,50 l50 draws from 100,50 to the left, ending at 50,50

The example shown will thus draw a red 'wire frame' square.

See also LINE and CIRCLE commands.

Note: The diagonal from 0,0 to 100,100 will be 100 * root(2) pixels long (i.e. 141)

Signifies the end of the program. When QBasic sees this command it usually comes up with a statement saying: "Press Any Key to Continue".

END TYPE / END DEF / END SUB / END FUNCTION / END IF / END SELECT

  • END TYPE     ends a TYPE definition .
  • END DEF      ends a DEF FN function definition .
  • END SUB      ends a SUB procedure definition .
  • END FUNCTION ends a FUNCTION procedure definition .
  • END IF       ends a multiline IF block .
  • END SELECT   ends a SELECT CASE block .

NOTE: If you are running QBasic on a Windows system, you will not be able to use this command.

This command helps you set an environment variable for the duration of the session. On exit from the QBasic.exe interpreter, the variables revert to their original values.

This checks if there are still more data values to be read from the file specified in (). EOF() returns a boolean / binary value, a one or zero. 0 if the end of file has not been reached, 1 if the last value in the file has been read (see also LINE INPUT)

Note that, since the INPUT is executed before UNTIL is reached, File.txt must contain at least one line of text - if the file is empty, you will receive an 'ERROR (62) Input past end of file'.

Used to erase all dimensioned arrays.

System variable holding a numeric value relating to the processing of the previous line of code. If the line completed without error, ERROR is set to 0. If the line failed, ERROR is set to one of the values shown below. Most commonly used to redirect program flow to error handling code as in :-

If ERROR is non=zero, program flow jumps to the line number or label specified. If ERROR is zero, program flow continues with the next line below.

To manually test your program and check to see if the error handling routine runs OK, ERROR can be set manually :-

Set ERROR = number

The error numbers are as follows:

Note that ERROR is set when execution fails, not when the code is 'read' - so, for example, a 'divide by 0' will be found before the result is assigned to a non-existent array variable or written to a non-existent file.

Allows the immediate exit from a subroutine or a loop, without processing the rest of that subroutine or loop code

Exits from a DEF FN function.

Exits from a DO loop, execution continues with the command directly after the LOOP command

Exits from a FOR loop, execution continues with the command directly after the NEXT command

Exits a FUNCTION procedure, execution continues with the command directly after the function call

Exits a SUB procedure.

FOR .. NEXT

The variable is set to the [start value], then program code is executed and at the Next statement the variable is incremented by 1 (or by the STEP value, if any is specified). The resulting value is compared to the [end value] and if not equal program flow returns to the line following the FOR statement.

For example:

200 199 198

Care must be taken when using STEP, since it is quite possible to step past the (end value) with the result that the FOR loop will run 'for ever' (i.e. until the user aborts the interpreter or an error occurs), for example :-

200 198 196 194 192 ... 0 -2 -4 ... -32768 ERROR overflow

Command processing jumps to the subroutine specified. When the RETURN command is encountered, processing returns to this point and continues with the line below the GOSUB.

Compares variables or strings. For example, if you wanted to examine whether or not a user-entered password was the correct password, you might enter: IF a$ = "password" THEN PRINT "Password Correct" Where a$ is the user entered password. Some operators include: "="- equal to "<"- less than (only used when variable or string is a number value) ">"- greater than (only used when variable or string is a number value) "<>"- does not equal "<="- less than or equal to (only used when variable or string is a number value) ">="- greater than or equal to (only used when variable or string is a number value) One can also preform actions to number values then compare them to other strings or variables using the if command, such as in the below examples: IF a+5 = 15 THEN PRINT "Correct" IF a*6 = b*8 THEN PRINT "Correct"

INCLUDE (QUICKbasic Only)

QUICKBasic supports the use of include files via the $INCLUDE directive:

Note that the include directive is prefixed with an apostrophe, dollar, and that the name of the file for inclusion is enclosed in single quotation mark symbols.

This is used when you want a program to function with key input from the keyboard. Look at this example on how this works:

You can use this in conjunction with the CHR$ command or type the letter (e.g. A).

Displays the String Literal, if a semi colon follows the string literal, a question mark is displayed, and the users input until they hit return is entered into the variable. The variable can be a string or numeric. If a user attempts to enter a string for a numeric variable, the program will ask for the input again. The String Literal is option. If the string literal is used, a comma (,) or semicolon (;) is necessary.

Reads a string / value from the specified file stream (see also LINE INPUT #)

Reads 4 values from the file that is OPEN as #1. a$ is assigned all text until a ',' (comma) or end of line is reached, b$ the next segment of text, then two numeric values are interpreted and assigned to n and m.

Note that, within the file, numbers can be separated by 'anything' - so, if a number is not found (for 'n' or 'm') on the current 'line' of the file, the rest of the file will be searched until a number is found. Input is then left 'pointing' at the position in the file after the last number required to satisfy the input statement (see also 'seek #' command)

Returns the character position of the start of the first occurrence of Find$ within Search$, starting at character position 'start%' in Search$. If Find$ is not found, 0 is returned. start% is optional (default = 1, the first character of Search$)

A$ is set to the N left most characters of B$.

returns "Get th"

See also RIGHT$(), MID$().

Early versions of the QBasic.exe command interpreter required use of the 'LET' command to assign values to variables. Later versions did not.

is equliavent to :-

Used for drawing lines in QBasic. The first X and Y are used as coordinates for the beginning of the line and the second set are used for coordinating where the end of the line is. You must put a SCREEN command at the beginning of the program to make it work.

Note. When in SCREEN 13, the Colour Number == the Palette number

LINE INPUT #

Reads a complete line as text characters from the file OPEN as stream #1 and places it in a$.

To find the 'end of line', the QBasic interpreter seaches for the 'Carriage Return' + 'Line Feed' (0x0D, 0x0A) characters. When reading text files created on UNIX/LINUX systems (where the 'Line feed' 0x0A is used on it's own to signify 'end of line'), LINE INPUT will not recognise the 'end of line' and will continue to input until the end of file is reached. For files exceeding 2k characters, the result is an "Out of String Space" Error as a$ 'overflows'. One solution is to use a text editor able to handle UNIX files to open and 'save as' before attempting to process the file using QBasic.

LOADIMAGE (QB64 Only)

(NOTE! The commands in this section refer to a third-party program called "QB64". Neither QUICKbasic nor Qbasic support _LOADIMAGE, _NEWIMAGE, OR _PUTIMAGE commands. Both QUICKbasic and Qbasic have a "SCREEN" command, but it works diffently in those languages than in QB64.)

_LOADIMAGE("image.jpg")

Shows an image. Must be used with the commands SCREEN, _NEWIMAGE and _PUTIMAGE.

DIM rabbit AS LONG SCREEN _NEWIMAGE(800, 600, 32) rabbit = _LOADIMAGE("rabbit.jpg") _PUTIMAGE (100,100), rabbit

Used to create a loop in the program. This command checks the condition after the loop has started. This is used in conjunction with the DO command.

Prints out text to a printer. The LPRINT command expects a printer to be connected to the LPT1(PRN) port. If a printer is not connected to LPT1, QBasic displays a "Device fault" error message.

If your printer is connected to a COM port instead, use the MS-DOS MODE command to redirect printing from LPT1 to COMx (for example, to redirect to COM1, use the following command:

If you need to cancel the redirection when finished, use the following command:

In the first use, a$ is set to the substring taken from string$ strating with character start% taking Length% characters. If length% is omitted, the rest of the line (i.e. start% and all the characters to the right) are taken.

In the second use, length% characters of string$ are replaced by b$ starting at start%. If length% is omitted, the rest of the line is replaced (i.e. start% and all the characters to the right)

See also LEFT$ RIGHT$ LEN

Returns the remainder of an integer divide of a by b

For example, 10 MOD 3 returns 1

NEWIMAGE(Only QB64!)

_NEWIMAGE is used to set a long variable as the screen dimensions, or can be used with the SCREEN command (See later in Appendix) to directly set the screen details. It is very useful as you can enlarge the SCREEN mode '13' which has RGB color settings if you find the default size too small.

Syntax: _NEWIMAGE(width,length,screen_mode)

  • width and length are long variables, while screen_mode is the screen mode format you wish to change.

where, 256 is the amount of colours

It is also used to prepare the window screen surface for the image you want to put (first load it using LOADIMAGE).

This opens a file. You have to give the DOS file name, for example:

Opens the existing file data.txt for reading as data stream #1. Since no path is specified, the file must be in the same folder as the QBasic.exe - if not, processing halts with a 'file not found' error

Opens an empty file named RUN.LOG in the C:\TEMP folder for writing data stream #2. Any existing file of the same name is replaced.

For VGA (SCREEN mode 13) only, sets the Palette entry to a new RGB color. The palette number must be in the range 1-256. The required colour is a LONG integer created from the sum of (required Blue * 65536) + (required Green * 256) + required Red.

RANDOMIZE will set the seed for QBasic's random number generator. With QBasic, it's standard to simply use RANDOMIZE TIMER to ensure that the sequence remains the same for each run.

The example is a mathematical operation to get a random number from 1 to 100.

INT stands for Integer, RND for Random and "*" stands for the limit upto which the random number is to be chosen. The "+ 1" is just there to ensure that the number chose is from 1 to 100 and not 0 to 99.

Note: Subsequent calls of this function do not guarantee the same sequence of random numbers.

Used in conjunction with the DATA command, this command lets QBasic read data. This is mostly used when dealing with large quantities of data like bitmaps.

When the interpreter encounters REM or " ' " (a single quote) at the start of a line, the rest of the line is ignored

Signifies that it is the end of a subroutines

RND will provide a random number between 0 and 1.

The example is a mathematical operation to get a random number from 1 to 100. RANDOMIZE TIMER will set the initial seed to a unique sequence. INT stands for Integer, RND for Random and "*" stands for the limit upto which the random number is to be chosen. The "+ 1" is just there to ensure that the number chose is from 1 to 100 and not 0 to 99.

Internally, the seed a 24-bit number, iterated in the following method: rnd_seed = (rnd_seed*16598013+12820163) MOD 2^24

Used to play notes and a score in QBasic on the PC speaker. The tones are indicated by letters A through G. Accidentals are indicated with a "+" or "#" (for sharp) or "-" (for flat) immediately after the note letter. See this example:

Whitespaces are ignored inside the string expression. There are also codes that set the duration, octave and tempo. They are all case-insensitive. PLAY executes the commands or notes the order in which they appear in the string. Any indicators that change the properties are effective for the notes following that indicator.

Displays text to the screen. The Argument can be a string literal, a string variable, a numeric literal or a numeric variable. All arguments are optional.

Saves data to the file that is 'OPEN FOR OUTPUT AS #[n]' or we can use ? symbol for print command

This command displays pixels, either one at a time or a group of them at once. For the command to work, the program must have a SCREEN command in it.

This command is used for displaying graphics on the screen. There are ten main types of screen modes that can be used in QBasic depending on the resolution that you want. Here is a list of what screen modes you can choose from:

SCREEN 0: Textmode, cannot be used for graphics. This the screen mode that text based programs run on.

SCREEN 1: 320 x 200 Resolution. Four Colours

SCREEN 2: 640 x 200 Resolution. Two Colours (Black and White)

SCREEN 7: 320 x 200 Resolution. Sixteen Colours

SCREEN 8: 640 x 200 Resolution. Sixteen Colours

SCREEN 9: 640 x 350 Resolution. Sixteen Colours

SCREEN 10: 640 x 350 Resolution. Two Colours (Black and White)

SCREEN 11: 640 x 480 Resolution. Two Colours

SCREEN 12: 640 x 480 Resolution. Sixteen Colours

SCREEN 13: 320 x 200 Resolution. 256 Colours. (Recommended)

Note. In SCREEN 13 you have a colour Palette of 256 colours. The PALETTE is pre-set by Windows however you can change the RGB values using the PALETTE command.

Repositions the 'input #' pointer to the beginning of the file.

Yields the 'sign' of a value, -1 if < 0, 0 if 0, 1 if > 0

The 'SHELL' command is used in Qbasic to issue a command to Command Prompt/Windows Shell . The 'Shell' command is used along with a string that contains commands that would be understood by any of the above software. The string enclosed commands are much like that of MS-DOS

Example: SHELL can be used with a 'DIR' command to make a directory of files in a certain folder or path.

Execution is suspended for n seconds

Unlike the BEEP command, this produces a sound from the PC speakers that is of a variable frequency and duration. The frequency is measured in Hertz and has a range from 37 to 32767. Put in one of these numbers in the frequency section. The duration is clock ticks that is defaulted at 18.2 ticks per second.

Converts a numeric value into a text (string) character

The numeric value is converted into text characters and placed into A$. Use to convert numbers into a text string.

1) If the result is positive, a leading 'space' is added (STR$(123) = " 123" and not "123" as might be expected). If the result is negative, instead of a space you get a '-' (minus sign), i.e. STR$(-123) = "-123" and not " -123" as might be expected from the positive behaviour.

2) When converting a float (mumb!, numb#) less than 0.1, the string value may be rendered in 'scientific notation', with 'D' used rather than '*10^' (for example "5.nnnnnnD-02" rather than " .05nnnnnn" or "5.nnnnnn*10^-02"). This only occurs when the number of significant digits needs to be preserved (so .03000000 is rendered as " .03", whilst .030000001 becomes " 3.0000001D-02"), again perhaps not what you might expect.

See also CHR$ for converting an ascii value into a string character.

See also LEFT$, MID$, RIGHT$ for extracting sub-strings from a line of text.

The .bas exits, the QBasic.exe interpreter is closed and 'control' passes to the Command Window c:\ prompt (or next line of a calling .cmd script etc.)

NOTE!: This only works when you start your program at the command prompt using the "/run" parameter! (EX: "Qbasic /run MyProg.bas") Otherwise, Qbasic assumes you opened your program to make changes, and thus "SYSTEM" drops you back at the editor screen.

Used in conjunction with the GOTO or IF condition commands. It tells the computer what to do if a certain condition has been met.

Usually used to input a number of variables.

This example will print all numbers from 400 to 500. Instead of declaring all values separately, we can get them all declared in one go.

Used to format the output of data from PRINT commands. Normally, the QBasic interpreter will print a number as 8 characters with as many leading spaces as necessary. To change this behavour, the USING command can be used to format the output. For example ..

THEN PRINT #1, USING "0##"; n; ELSE PRINT #1, USING "00#"; n;

.. will output n from 0 to 999 with leading zeros. Note the ';' after the n. This means 'don't start a new line' and results in the next PRINT #1 adding data directly after the comma (',') Qbasic automatically inserts instead of a line.

Converts the [variable string] contents into a numeric value so it can be used in calculations. If (name) is an INTEGER type, the VAL is rounded down. See also STR$.

X = VAL(A$) + VAL(B$)

PRINT A$; " + "; B$; " ="; X

WHILE ... WEND

The condition is tested and if true (or NOT true) the [program] code is executed until WEND is reached, at which point control passes back to the WHILE line.

While the end of file #1 has not been reached, read each complete line and write it to file #2.

Unlike FOR and DO, it is not possible to EXIT from a WHILE loop

ASCII Chart

ASCII Character Codes 0-127

The authors of this work are:

Faraaz Damji (Frazzydee) Adam Colton Gareth Richardson (Grich) Debanshu Das

assignment statement in qbasic

  • Book:QBasic

Navigation menu

Community QBasic

Rebooting the QBasic we all know and love!

Gets keyboard input.

[;] [ {; ,}]

A semicolon immediately after INPUT directs QBasic to leave the cursor on the same line after the user presses Enter.

prompt is the optional prompt INPUT displays on the screen.

A semicolon after the prompt directs INPUT to display a question mark after the prompt.

A comma after the prompt directs INPUT to suppress the question mark.

variables is the list of variables to input. Separate multiple variables with commas.

If you enter a type other than the expected variable type or enter too many or too few values, INPUT displays the message Redo from start , and you must reenter the data.

The user must separate multiple entries with commas.

The variable names in the list may be numeric or string variable names (including subscripted variables).

No assignment of input values is made until an acceptable response is given.

When an INPUT statement is encountered during program execution, the program halts, the prompt string is displayed, and the operator types in the requested data. Strings that input to an INPUT statement need not be surrounded by quotation marks unless they contain commas or leading or trailing blanks.

When the operator presses the RETURN key, program execution continues.

INPUT and LINE INPUT statements have built-in PRINT statements. When an INPUT statement with a quoted string is encountered during program execution, the quoted string is printed automatically (see the PRINT statement).

The principal difference between the INPUT and LINE INPUT statements is that LINE INPUT accepts special characters (such as commas) within a string, without requiring double quotation marks, while the INPUT statement requires double quotation marks.

  • INPUT# , INPUT$ , LINE INPUT

QBasic Commands and Statements-2023

QBasic  language is a variant of  Basic programming  developed by Microsoft in 1985. It was developed to make computer programs and various utilities for MS-DOS and windows 98/95 Operating system. It is easy to code and very easy to understand.

Table of Contents

If you are searching for  Qbasic commands for class 6  or  Qbasic statements for class 7,  then this is the right article for you.

Here in this post, we will learn about basic commands and statements that will help you to understand the concept of how a computer understands what you have programmed.

If you want to know about Qbasic check  QBASIC Programming – Beginner’s Friendly

QBasic commands  are available as an external command in the following version of Microsoft Operating Systems:

  • All Versions of MS-DOS
  • Windows 95 and

However, the modern operating system(Windows 10, 11) doesn’t have these external commands built-in. To use the qbasic commands you need to install QBasic in windows first.

Here in this article, we will talk about both  External QBasic commands  and  QBasic statements .

First, let us understand what are external and internal commands and Qbasic Statements.

What are External and Internal Commands?

External commands  are those commands which are not in-built in  MS-DOS  or  Windows . To read those external files we need an internal file that can interpret those commands. In a modern-day operating system, the QBasic commands are not in-built so those QBasic commands are external commands. We need to install QBasic on our computer system that will then interpret those External Commands.

However,  internal commands  are those commands that are in-built commands in your operating system like windows. There is no need for any external software or files to interpret those commands.

The internal commands are the same in every windows version. Examples of Internal commands are  del, mkdir, copy, cls, date, ren, vol  etc. you can get all the commands by typing HELP in the command prompt in windows.

All versions of MS-DOS and Windows have the  same internal commands  but may have  different external commands .

What is a QBASIC statement/command?

A command or instructions in a QBASIC is called a  statement . Some are executable commands while some are non-executable commands. Executable statements are those that have a specific action while non-executable are the ones which is used to specify arguments, initial value or provide characteristics to a data

Since we now know the meaning of external commands, let us see some of the  External QBASIC Commands .

List of External QBASIC commands

First, start the MS-DOS QBasic environment.

It allows us to use a monochrome monitor with a color graphics card.
It starts the MS-DOS editor
 Provides the fastest update of the CGA screen (works only with machines using CGA monitors). If you see some dot flickering on your screen that means your hardware cannot fully support this option.
 display the maximum number of lines on your screen.
It converts IEEE numbers to Microsoft-Binary-Format numbers.
This command allows us to use a monitor that does not support high Intensity.
 To execute a QBASIC program.   – [[drive:][path]filename].

List of QBasic Programming Statements

Here are some of the basic QBASIC statements listed with syntax and examples.

Print Statement

The PRINT command prints the data or text on the output screen. If you want to print a sentence or string then you have to put inside double quotes (“  ”) and if you want to print a variable or a number, write after the PRINT command.

Syntax : PRINT

If it is a variable or a number,

If it is a string,

INPUT statement

The INPUT command is used to take data from a user. It can accept both strings and numbers.

If the input data is a number then the variable name is written directly after the INPUT command.

Syntax : INPUT [“string”] variable

And if the input data is a string then the variable name in which it is to be stored is written after INPUT command followed by $sign

CLS Statement

CLS means clear screen. This command is used to clear the screen if there are some output or results on your screen that you want to clear or erase.

Syntax : CLS

LET statement

The LET command is used to assign a value to a variable. The value can be a string or number.

Syntax : LET [variable] = [expression]

END Statement

The END command is used to terminate a QBasic program. This statement is written at the end of a program to let the computer know that it is the end of the program and to terminate the process.

Syntax : END

REM statement

REM is a remark command. This is a non-executable statement. It is written within a single quote.

Syntax : REM

LINE INPUT statement

The LINE INPUT statement allows to input data at a time and assign it to a single variable.

Syntax : LINE INPUT “string”; string variable

So these are some of the basic Qbasic commands and Qbasic statements that will help you to get started with the programming language.

Related Articles:

Qbasic Control Statements with Examples

Download Qbasic (QB64) Free for Windows 10 and 11

Qbasic Programming Examples and Exercises

Qbasic color statement.

Qbasic Looping statements with Examples

Free QBasic Online Compilers – Online Editors

QBASIC Programming – Beginner’s Friendly

Related Posts

Qbasic Color statement

Simply Coding

Quick Revision of QBASIC Commands and Programs

  • Categories QBasic

Below are QBasic Commands and questions.

Q 1.what is qbasic.

QBasic is a version of BASIC programming language developed by Microsoft Corporation.

Q 2.What is full form of BASIC?

Full form of Basic is Beginners All Purpose Symbolic Instruction Code .

Q 3.Why is QBasic so popular?

QBasic is popular as

  • It is available as freeware and many tutorials, forums are available to learn the language.
  • It is easy to understand and write programs using a IDE (Integrated Development Environment)

Q 4.What is LET statement?

LET statement is used to initialize variables with values at the start of the program. Data is stored in variables by using LET statement.

e.g. LET A = 12

Q 5.What is READ DATA statement?

READ … DATA statement allows us to read many data items in a single statement. The syntax for it is as below

Read var1, var2

DATA val1, val2, val3

Key Points:

  • DATA statement can appear anywhere in the program but before END
  • Read statement reads the data in the order in which they are written in DATA statement.
  • If DATA values are less than that required by READ, then “Out of DATA” message is displayed.
  • If there is a mismatch in data type of variable, it will give an error.

Q 6.What are functions? What are the advantages of using functions?

Functions are ready made programs that can be used anywhere in the programs. The advantages of functions are

  • It helps to make our work simpler and faster
  • It reduces the length of the program

Q 7.What are different types of Standard Library Functions in QBasic?

There are three types of functions in QBASIC.

  • Mathematical Functions
  • String Functions
  • Conversion Functions

Q 8.What are various Mathematical Functions?

Different Mathematical Functions are.

  • SYNTAX: ABS(n)
  • EXAMPLE: ABS (-5) gives output as 5
  • SYNTAX: SGN(n)
  • EXAMPLE: SGN (-5) gives output as -1
  • SYNTAX: INT(n)
  • EXAMPLE: INT (-5.3) gives output as -6
  • SYNTAX: FIX(n)
  • EXAMPLE: FIX (5.3) gives output as 5
  • SYNTAX: CINT(n)
  • EXAMPLE: INT (5.6) gives output as 6
  • SYNTAX: SQR(n)
  • EXAMPLE: SQR (4) gives output as 2

Q 9.What are various String Functions?

String functions are used for working with Strings. Different String Functions are –

  • SYNTAX: String1 + String2
  • EXAMPLE: “Name ” + “Surname”
  • SYNTAX: LEN(String)
  • EXAMPLE: LEN( “name”) gives output as 4
  • SYNTAX: RIGHT$(String,n)
  • EXAMPLE: RIGHT$( “name”, 2) gives output as “me”
  • SYNTAX: LEFT$(String,n)
  • EXAMPLE: LEFT$( “name”, 2) gives output as “na”
  • SYNTAX: MID$(String,m,n)
  • EXAMPLE: MID$( “name”, 2,1) gives output as “m”
  • SYNTAX: UCASE$(String), LCASE$(String)
  • EXAMPLE: UCASE$( “name”) gives output as “NAME”
  • SYNTAX: STRING$(n,Character)
  • EXAMPLE: STRING$( 2,”x”) gives output as xx
  • SYNTAX: SPACE$(n)
  • EXAMPLE: SPACE$( 5 ) gives output as “ ”

Q 10.  What are various Conversion Functions?

Conversion functions are used to perform conversion operations on variables.

  • SYNTAX: ASC(Character)
  • EXAMPLE: ASC(“A”) will return 65
  • SYNTAX: CHR$(n)
  • EXAMPLE: CHR$(65) will return A
  • SYNTAX: STR$(n)
  • EXAMPLE: ASC(234) will return string “234”
  • SYNTAX: VAL(String)
  • EXAMPLE: VAL(“23”) will return 23

Q 11.What is ASCII?

ASCII Stands for American Standard Code for Information Interchange . There are 256 ASCII codes from 0 to 255 . Codes for common alphabets are as following

  • A to Z = 65 to 90
  • a to z = 97 to 122
  • 0 to 9 = 48 to 57

QBasic Questions

Q 1.  fill in the blanks.

  • ______________ function returns length of the string
  • ______________ function return n number of spaces

Ans. SPACE$()

  • ______________ function returns n character from right of the string

Ans. RIGHT$()

  • ______________ function converts string to number
  • ______________ function returns ASCII code of character
  • ______________ function returns a value indicating the sign of number
  • ______________ function converts all characters to uppercase

Ans. UCASE$()

  • ______________ function truncates the fractional part of the number
  • ______________ function returns a substring from any position

Ans. MID$()

  • ______________ function rounds off a number to the nearest integer

Ans. CINT()

  • ______________ function returns n number of characters from right of the string
  • ______________ function returns nearest integer which is less than or equal to value
  • ______________ function returns character of given ASCII code

Ans. CHR$()

  • ______________ function converts numeric value to string

Ans. STR$()

  • ______________ operator can concatenate string.
  • ______________ statement is used to initialize a variable at the start of the program
  • ______________statement is used to read many data items in single statement

Ans. READ … DATA

  • The values stored in DATA statement are separated by ______________.
  • DATA statement must appear before the ______________
  • ______________ message is displayed if DATA statement contains less values than what is required by READ statement.

Ans. “Out of DATA”

  • _______, _______, _________are three types of standard library functions.

Ans. Mathematical,String, Conversion.

Q 2.What is full form of following

  • American Standard Code for Information Interchange
  • Integrated Development Environment
  • Beginners All Purpose Symbolic Instruction Code

Q 3.What is the output of following statements

  • CINT(-22.5)
  • CINT(-22.6)

Q 4.Identify if it is the right syntax for the command

  • LEN$(“ABC”)
  • SGN(“1.23”)
  • RIGHT(“ABC”,2)
  • LEFT$(2,”ABC”)
  • STRING(2,”ABC”)
  • MID$(2,4,”ABC”)
  • RIGHT$(“ABC”,2)
  • ASC(“ABC”) – Will only return ASCII value of A
  • LEFT$(”ABC”,2)
  • STRING(2,”ABC”) – Will replicate A 2 times
  • MID$(”ABC”, 2,4)

Q 5.What is the output of following statements

  • LEN(“I AM”)
  • RIGHT$(“SIMPLY”,10)
  • LEFT$(“SIMPLY”,3)
  • MID$(“SIMPLY”,2,3)
  • UCASE$(“Simply”)
  • STRING$(4,“Simply”)
  • PRINT “SIMPLY”;SPACE$(4);”CODING”
  • PRINT “SIMPLY”, “CODING”
  • SIMPLY CODING

Q 6.What is the output of following statements

  • VAL(“22.4”)

Q 1.  Write a program to enter your name and print it?

Q 2.  write a program to find the area of rectangle., q 3.write a program to find the area of the triangle., q 4.write a program to find the area of the circle., q 5.write a program to find the circumference of the circle., q 6.write a program to find out the simple interest., q 7.write a program to find the average of three different numbers., q 8.write a program to enter any number and find out whether it is negative or positive., q 9.write a program to enter any number and find out whether it is even or odd using select case statement., q 10. write a program to check the numbers between 1 & 3., q 11. write a program to enter any alphabet and test alphabet is ‘a’ or not using the select case statement., q 12. write a program to enter any alphabet and find out whether the number is vowel or alphabet., q 13. generate the following numbers using for….next…..loop.    1,2,3,4,…,50, q 14. generate the following numbers using for….next…..loop.   –    2,4,6,8,10,…50.

User Avatar

Previous post

Computer Networking Notes and Questions to revise in 1 Hour

Ms access notes and questions, leave a reply cancel reply.

You must be logged in to post a comment.

Login with your site account

Remember Me

Not a member yet? Register now

Register a new account

I accept the Terms of Service

Are you a member? Login now

Academia.edu no longer supports Internet Explorer.

To browse Academia.edu and the wider internet faster and more securely, please take a few seconds to  upgrade your browser .

Enter the email address you signed up with and we'll email you a reset link.

  • We're Hiring!
  • Help Center

paper cover thumbnail

THE PROGRAMMING KNOW-HOW USING QBASIC PROGRAMMING TECHNIQUES

Profile image of FALANA  TAYE FREDRICK

The aims and objectives of this book is towards adequate and effective knowledge of programming using QBasic.

Related Papers

Hizballah Arham

assignment statement in qbasic

FALANA TAYE FREDRICK

ABSTRACT This study was carried out on the design and implementation of post utme online examination system, a case study of Adekunle Ajasin University, Akungba - Akoko, Ondo State. Online Examination System is a system based on carrying out test and examination, which were carried out manually with the aid of computer and internet technology Mustakerov & Borissova (2011). The project work support and implement the three structural layers proposed by Aimin & Jipeng (2009), the three layers were the administrator, Student and instructor, also the architecture of Jin & Ma (2008) which focus on this layers were adopted in the development. Furthermore, Wilson (2004) investigated the extent the feedback process affects the student performance by comparing with the students who receive classical face-to-face education. The author emphasized that student feedbacks may render evaluation process more efficient. The current study is inline with Wilson (2004) and also with the view of Crisp & Ward (2008), on the other hand, that getting feedbacks in the systems with too many students can only be achieved with the aid of online systems. And lastly, in their study, Shen et al. (2001) emphasized the importance of adjustment and update processes based on student feedbacks for proper execution of online examination. The current research makes use of this trend in the integration of feedback system in Adekunle Ajasin University, Akungba - Akoko online examination system. In addition, there are other potentially problematic issues to consider. There are consistent situational or environmental characteristics of situations where students cheat (Leming, 1979; Maramark & Maline, 1993). Most cheaters recognize that cheating is wrong, but believe that they are in special circumstances that make it right for them to cheat (Sykes & Matza, 1957). The second of the problems concerns enrolment. No matter how securely the system is designed, if the correct person is not enrolled, the use of biometrics does not help (Ashbourn, 1999; Boves & Koolwaaij, 1998; Schneier, 1999). Although these disadvantages should not discourage developers from creating online support, they should be considered during planning and designing stages (Aimin & Jipeng 2009) this serve as a motivation for the current project. Primary contribution of this study is the proposed online examination system having an integrated and flexible structure. The system manages a number of functions such as collection of feedbacks from students, generating reports and submitting them to the managers and providing proposals in the decision-making processes by help of analysis within a single module as distinct from the other studies found in the literature.

Loading Preview

Sorry, preview is currently unavailable. You can download the paper by clicking the button above.

RELATED TOPICS

  •   We're Hiring!
  •   Help Center
  • Find new research papers in:
  • Health Sciences
  • Earth Sciences
  • Cognitive Science
  • Mathematics
  • Computer Science
  • Academia ©2024

Myschool.ng

  • Username Password Remember me Sign in New here ? Join Us

Project Topics and Materials, Post-UTME past questions - Download now or upload yours to get paid

  • Computer Studies
  • The LET statement in...

The LET statement in QBASIC

  • A. allows users to assign a value to a variable.
  • B. allows the users to enter data into the computer during program execution.
  • C. checks the errors within the code.
  • D. allows the users to enter data into the computer from

NECO June/July 2024 - Get offline past questions & answers - Download objective & theory, all in one app 48789

Correct Answer: Option A

Explanation.

The LET statement in QBASIC allows users to assign a value to a variable. In QBASIC and other programming languages, the LET statement is used to assign a value to a variable. It is an optional keyword, and in most cases, you can simply use the variable name followed by the assignment operator (=) and the value you want to assign to the variable. For example: LET x = 10 This statement assigns the value 10 to the variable x.

Contributions ({{ comment_count }})

Please wait..., modal title, {{ feedback_modal_data.title }}, quick questions.

assignment statement in qbasic

Post your Contribution

Please don't post or ask to join a "Group" or "Whatsapp Group" as a comment. It will be deleted. To join or start a group, please click here

{{ quote.posted_by.display_name }}

Navigation Menu

Search code, repositories, users, issues, pull requests..., provide feedback.

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly.

To see all available qualifiers, see our documentation .

  • Notifications You must be signed in to change notification settings

A minimal BASIC interpreter designed with C++, which includes expression parsing, expression evaluation, statement execution and runtime context maintenance

ZhaoHaoRu/QBasic-Interpreter

Folders and files.

NameName
2 Commits

Repository files navigation

Introduction.

This project builds a minimal BASIC interpreter.

The programming language BASIC—the name is an acronym for Beginner’s All-purpose Symbolic Instruction Code—was developed in the mid-1960s at Dartmouth College by John Kemeny and Thomas Kurtz. It was one of the first languages designed to be easy to use and learn. Although BASIC has now pretty much disappeared as a teaching language, its ideas live on in Microsoft’s Visual Basic system, which remains in widespread use.

Functions & Commands

Table 1. statements implemented in the minimal version of basic.

Statements Description
REM This statement is used for comments. Any text on the line after the keyword REM is ignored.
LET This statement is BASIC’s assignment statement. The LET keyword is followed by a variable name, an equal sign, and an expression. As in C++, the effect of this statement is to assign the value of the expression to the variable, replacing any previous value. In BASIC, assignment is not an operator and may not be nested inside other expressions.
PRINT In minimal BASIC, the PRINT statement has the form: 'PRINT exp', where exp is an expression. The effect of this statement is to print the value of the expression on the console and then print a newline character so that the output from the next PRINT statement begins on a new line.
INPUT In the minimal version of the BASIC interpreter, the INPUT statement has the form:'INPUT var', where var is a variable read in from the user. The effect of this statement is to print a prompt consisting of the string " ? " and then to read in a value to be stored in the variable. (The string " ? " should display in the command input edit box in GUI.)
GOTO This statement has the syntax: 'GOTO n', and forces an unconditional change in the control flow of the program. When the program hits this statement, the program continues from line n instead of continuing with the next statement. Your program should report an error if line n does not exist.
IF This statement provides conditional control. The syntax for this statement is: 'IF exp1 op exp2 THEN n ',where exp1 and exp2 are expressions and op is one of the conditional operators =, <, or >. If the condition holds, the program should continue from line n just as in the GOTO statement. If not, the program continues on to the next line.Note that the conditional operators (=, <, >) are not parts of expressions.
END Marks the end of the program. Execution halts when this line is reached. This statement is usually optional in BASIC programs because execution also stops if the program continues past the last numbered line.

Table 2. Commands to control the BASIC interpreter

Commands Description
RUN This command starts program execution beginning at the lowest-numbered line. Unless the flow is changed by GOTO and IF commands, statements are executed in line-number order. Execution ends when the program hits the END statement or continues past the last statement in the program.
LOAD This command loads a file containing statements and commands. Statements and commands should be stored (also displayed in GUI) and executed respectively, as if they were entered into input box in order. A prompt window should be displayed when this command is entered. The window asks users to choose the file to load.
LIST This command lists the steps in the program in numerical sequence. It has been required to be implemented in the previous version of this project. In the new version, your interpreter should be able to display all the codes that have been entered in real time, so there is no need to implement this command.
CLEAR This command deletes the program so the user can start entering a new one.
HELP This command provides a simple help message describing your interpreter.
QUIT Typing QUIT exits from the BASIC interpreter.

Syntax tree display

Syntax tree is one abstract representation of program. More specifically, every statement in the program can be represented as a tree. The structure of the syntax tree can be seen as the steps of the computation of the expression in the statement. The node of the tree can be identifier definition, assignment, function call, expression computation and conditional or unconditional branch. In my interpreter implementation, the computation is made along the syntax tree from leaf node to root. Because the connection structures of the tree are determined by the computation rules, e.g. operator priority and association. In my implementation, the syntax tree is constructed in infix notation.

Haoru Zhao - [email protected]

This project is licensed under the MIT License - see the LICENSE file for details

QBasic 1.1: SELECT CASE Statement

Explanation, select case statement, worth knowing.

Useful and cross-version information about the programming environments of QBasic, QuickBasic and Visual Basic for DOS.

You are here: References Overview > QBasic 1.1 Commands List > SELECT CASE Statement

testexpression
expressionlist1
 [statementblock-1]
expressionlist2
 [statementblock-2]...
 [statementblock-n]

Description / Parameter(s)

Any numeric or string expression.
One or more expressions to match testexpression.
The IS keyword must precede any relational operators in an expression.
One or more statements on one or more lines.
expression[,expression]...
expression TO expression
IS relational-operator expression
Any numeric or string expression compatible with testexpression.
One of the following relational operators: <, <=, >, >=, <>, or =.
See also: 

IMAGES

  1. QBASIC

    assignment statement in qbasic

  2. [HINDI] Assignment statement

    assignment statement in qbasic

  3. Write a program in c for addition, subtraction, multiplication, division and modulus of two

    assignment statement in qbasic

  4. PDF Télécharger qbasic by example Gratuit PDF

    assignment statement in qbasic

  5. Computer Programming: Assignment Statements in QBasic, Java and Python

    assignment statement in qbasic

  6. PPT

    assignment statement in qbasic

VIDEO

  1. Tutorial 1 assigning value to a variable

  2. 43 Augmented Assignment statement

  3. Formal Methods, Lecture 4 Recap

  4. BD31303 FINANCIAL STATEMENT ANALYSIS GROUP ASSIGNMENT (Travel Now)

  5. How To Solve QBASIC Sorting Question 2(Ascending Order)

  6. 6 storing values in variable, assignment statement

COMMENTS

  1. QBasic 1.1: KEY (Assignment) Statement

    Description / Parameter (s) The number of a function key. Use 1 through 10 for function keys F1 through F10. Use 30 and 31 for function keys F11 and F12 on extended keyboards. A string of up to 15 characters that is returned when the function key is pressed. Displays the assignments for each key. Turns on the function-key display line.

  2. QBasic 1.1 Commands List

    QBasic Online Manual. This section contains the complete command set (keywords, functions, statements, operaters) of QBasic 1.1, listed in alphabetical order. After clicking a keyword, the corresponding information will be displayed: Description, Syntax, Parameters, Examples and related Links.

  3. Computer Programming: Assignment Statements in QBasic, Java ...

    This video is a continuation of the previous (Variable Declaration Statements). we discussed assignment statements as one of the means through which data can...

  4. KEY Statement (Assignment)

    function keys F1 through F10. Use 30 and 31 for. function keys F11 and F12 on extended keyboards. stringexpression$ A string of up to 15 characters that is returned. when the function key is pressed. LIST Displays the assignments for each key. ON Turns on the function-key display line.

  5. QBASIC

    The definition and usage of assignment and input statement in QBASIC is explainedViSkill is India's best YouTube curated skill app. Why pay for courses or se...

  6. Fundamentals of QBASIC: Commands and Statements

    It is optional for assignment statement. Reason — LET is an optional statement. Every BASIC program need not use LET statement. Question 4. Which of the following is the correct extension of QBASIC file?.Basic.EXE.BAS.BASIC; Answer.BAS. Reason — All QBASIC programs are saved with the extension .bas. Question 5

  7. QBasic 1.1: LET Statement

    Any expression that provides a value to assign. Use of the optional LET keyword is not recommended. The variable=expression assignment statement performs the same action with or without LET. QBasic 1.1 Commands List - Keyword Reference: LET Statement Assigns the value of an expression to a variable.

  8. QBasic Tutorial: QBasic Programming for Dummies

    A statement is an instruction within a program. The four types of statements are; Declaration Statement; Assignment Statement; Control Statement; Input/Output Statement; The command is the instructions to the computer to do something to a program as printing, saving etc. Character Set is a set of characters which are valid in Q Basic.

  9. The QP7 Programming Page: Qbasic Tutorial

    SECTION 3 - MORE ADVANCED DATA MANIPULATION. There are numerous methods to manipulate data and present it to the user in QBasic. One is called an array. An array is a variable which can contain more than one value. For example, you might have an array called a, and yo u could assign data to the members of that array.There might be a value for a(1), and a different value for a(6).

  10. LET

    Rebooting the QBasic we all know and love! LET. Assigns a value to a variable. Syntax [LET] variable = expressionComments. LET is an optional keyword used in assignment statements to assign a value to a variable.. Example

  11. Qbasic Statements

    There are several different types statements in QBASIC Programming language. For example, CLS statement clears the screen, PRINT statement displays output and INPUT statement takes the input from the users. ... It is an an assignment statement which is used to assign value to a variable. LET is an optional statement. Syntax : Let x = 5. 4 ...

  12. Qbasic Programming Examples and Exercises

    This post has beginner-level Qbasic examples and exercises that will help you to understand the concept of variable and Qbasic statements like INPUT, PRINT, CLS, etc. Before getting started it is important to know the basic Qbasic statements or QBasic commands first. Read more about it, check: - QBasic Commands and Statements-2020

  13. QBasic/Appendix

    The code segment to use is set using DEF SEG. Normally QBasic will push the address of arguments, but if an argument is preceded by BYVAL the value of the argument will be pushed. Note that because QBasic pushes the arguments from left to right, if you provide three arguments for example the stack will look like this:

  14. Statements in QBASIC

    A statement is a set of instructions written by using keywords or commands of QBASIC. LET is an assignment statement. It is used to assign the value to a variable. The remarks may be useful in a program to explain about different kinds of statements and user defined words. PRINT statement provides output on the screen.

  15. QBasic/Full Book View

    QBasic has a random number statement, RND, that generates a random decimal between 0 and 1. You can think of it as a random percent. At first, this may seem like an odd way to generate random numbers. However, with a little math it is very easy to manipulate this to provide numbers in whatever range you want.

  16. INPUT

    variables is the list of variables to input. Separate multiple variables with commas. If you enter a type other than the expected variable type or enter too many or too few values, INPUT displays the message Redo from start, and you must reenter the data. The user must separate multiple entries with commas. The variable names in the list may be ...

  17. QBasic Commands and Statements-2023

    QBasic Commands and Statements-2023. By Izzaz / September 16, 2023. QBasic language is a variant of Basic programming developed by Microsoft in 1985. It was developed to make computer programs and various utilities for MS-DOS and windows 98/95 Operating system. It is easy to code and very easy to understand.

  18. QBasic 1.1: IF...THEN...ELSE Statement

    Any expression that can be evaluated as true (nonzero) or false (zero). statementblock-1. statementblock-2. statementblock-n. One or more statements on one or more lines. statements. One or more statements, separated by colons.

  19. QBasic Commands and Programs

    Below are QBasic Commands and questions. Q 1.What is QBasic? Ans: QBasic is a version of BASIC programming language developed by Microsoft Corporation. Q 2.What is full form of BASIC? ... Q 4.What is LET statement? Ans: LET statement is used to initialize variables with values at the start of the program. Data is stored in variables by using ...

  20. THE PROGRAMMING KNOW-HOW USING QBASIC PROGRAMMING TECHNIQUES

    QBasic Assignment Statement The assignment statement (=) is used to assign a value, data, string or message to a particular variable. The following keywords are essential while dealing with assignment qQ QBasic Programming By Falana Taye Fredrick Page 19 HEADWORLD TECHNOLOGY TRAINING CERTIFICATION Complete Version @ $8.9 Only. statement in QBasic.

  21. The LET statement in QBASIC

    In QBASIC and other programming languages, the LET statement is used to assign a value to a variable. It is an optional keyword, and in most cases, you can simply use the variable name followed by the assignment operator (=) and the value you want to assign to the variable. For example: This statement assigns the value 10 to the variable x.

  22. ZhaoHaoRu/QBasic-Interpreter

    This statement is BASIC's assignment statement. The LET keyword is followed by a variable name, an equal sign, and an expression. As in C++, the effect of this statement is to assign the value of the expression to the variable, replacing any previous value. In BASIC, assignment is not an operator and may not be nested inside other expressions ...

  23. QBasic 1.1: SELECT CASE Statement

    PRINT "Choose stock investment plan." CASE 2 TO 4. PRINT "Moderate to high risk and potential return." PRINT "Choose mutual fund or corporate bonds." CASE 1. PRINT "No risk, low return." PRINT "Choose IRA." SELECT CASE Statement Executes one of several statement blocks depending on the value of an expression.