Thursday, 1 January 2015

operator precedence to solve logical errors

Operator Precedence in BASIC


( ) parentheses
1
^ (Exponent)
2
- (Negation)
3
*, / ( Multiplication or Division)
4
MOD (Modulus)
5
+, - ( Addition or Subtraction)
6
\ (Integral Division)
7
<>, <=, >=, <, >. (Relational operators)
8
NOT
9
AND
10
OR
11
= ( assignment Operator)
12

types of error in gw basic

Types of errors in GW-BASIC
Usually there are three types of viruses in GW-BASIC, which are as follows:

Syntax error:
A Syntax Error occurs when the program violates one or more grammatical rules of the programming language.These errors are detected at the time ofcompiling of that program.
Logical error:
A Logical Error occurs when a program follows a wrong logic. The compiler or interpreter does not report any error mesage for a logical error. These are the most dificult errors to locate. The Logical Errors can be identified by looking at the wrong output of the program and throughly testing the program.
Runtime error:

This error occurs when program follows an illegal function call. For example when we try to divided a number by zero such as 4/0.




Rules for Naming a Variable

1- A Variable name cannot be more than 40 characters.

2- The name of Variable may contain alphabets (both lower case and upper case) numbers and decimal points.

3- The first character in name of Variable must be an Alphabet.

4- Key /Reserved words of BASIC cannot be used as Variables.


5- Blank space is not allowed in names of Variables.
6- Last character of variable name should indicate the type of variable.

Examples of Correct Variable Names:
c_ls
xyc
x1y1
xyz1
_xyz
_cls


Examples of Wrong Variable Names:
cls(Because rule no 4 broken)
x y c(Because rule no 5 broken)
x$y$1$(Because rule no 6 broken)
1xyz(Because rule no 3 broken)
_xyzasdasdddddddddddddddddddddddsdasda
asdasdasdasdadasdasdaasdas(Because rule no 1 broken)




file handling in gw basic(complete program where file open closed and edit)

files been opened then edited and then closed

all program related arrays in gwbasic including (Sum,Product,Reverse order,Square And multiple dimension array)







all the error with thier codes which appear while programming in gw basic compiler

Error Codes and Messages
Code
Message
1
NEXT without FOR
NEXT statement does not have a corresponding FOR statement. Check variable at FOR statement for a match with the NEXT statement variable.
2
Syntax error
A line is encountered that contains an incorrect sequence of characters (such as unmatched parentheses, a misspelled command or statement, incorrect punctuation). This error causes GW-BASIC to display the incorrect line in edit mode.
3
RETURN without GOSUB
A RETURN statement is encountered for which there is no previous GOSUB statement.
4
Out of DATA
A READ statement is executed when there are no DATA statements with unread data remaining in the program.
5
Illegal function call
An out-of-range parameter is passed to a math or string function. An illegal function call error may also occur as the result of:
a negative or unreasonably large subscript
a negative or zero argument with LOG
a negative argument to SQR
a negative mantissa with a noninteger power
a call to a USR function for which the starting address has not yet been given
an improper argument to MID$, LEFT$, RIGHT$, INP, OUT, WAIT, PEEK, POKE, TAB, SPC, STRING$, SPACE$, INSTR, orON...GOTO
6
Overflow
The result of a calculation is too large to be represented in GW-BASIC's number format. If underflow occurs, the result is zero, and execution continues without an error.
7
Out of memory
A program is too large, has too many FOR loops, GOSUBs, variables, or expressions that are too complicated. Use the CLEAR statement to set aside more stack space or memory area.
8
Undefined line number
A line reference in a GOTO, GOSUB, IF-THEN...ELSE, or DELETE is a nonexistent line.
9
Subscript out of range
An array element is referenced either with a subscript that is outside the dimensions of the array, or with the wrong number of subscripts.
10
Duplicate Definition
Two DIM statements are given for the same array, or a DIM statement is given for an array after the default dimension of 10 has been established for that array.
11
Division by zero
A division by zero is encountered in an expression, or the operation of involution results in zero being raised to a negative power. Machine infinity with the sign of the numerator is supplied as the result of the division, or positive machine infinity is supplied as the result of the involution, and execution continues.
12
Illegal direct
A statement that is illegal in direct mode is entered as a direct mode command.
13
Type mismatch
A string variable name is assigned a numeric value or vice versa; a function that expects a numeric argument is given a string argument or vice versa.
14
Out of string space
String variables have caused GW-BASIC to exceed the amount of free memory remaining. GW-BASIC allocates string space dynamically until it runs out of memory.
15
String too long
An attempt is made to create a string more than 255 characters long.
16
String formula too complex
A string expression is too long or too complex. Break the expression into smaller expressions.
17
Can't continue
An attempt is made to continue a program that
Has halted because of an error
Has been modified during a break in execution
Does not exist
18
Undefined user function
A USR function is called before the function definition (DEF statement) is given.
19
No RESUME
An error-trapping routine is entered but contains no RESUME statement.
20
RESUME without error
A RESUME statement is encountered before an error-trapping routine is entered.
21
Unprintable error
No error message is available for the existing error condition. This is usually caused by an error with an undefined error code.
22
Missing operand
An expression contains an operator with no operand following it.
23
Line buffer overflow
An attempt is made to input a line that has too many characters.
24
Device Timeout
GW-BASIC did not receive information from an I/O device within a predetermined amount of time.
25
Device Fault
Indicates a hardware error in the printer or interface card.
26
FOR Without NEXT
A FOR was encountered without a matching NEXT.
27
Out of Paper
The printer is out of paper; or, a printer fault.
28
Unprintable error
No error message is available for the existing error condition. This is usually caused by an error with an undefined error code.
29
WHILE without WEND
A WHILE statement does not have a matching WEND.
30
WEND without WHILE
A WEND was encountered without a matching WHILE.
31-49
Unprintable error
No error message is available for the existing error condition. This is usually caused by an error with an undefined error code.
50
FIELD overflow
A FIELD statement is attempting to allocate more bytes than were specified for the record length of a random file.
51
Internal error
An internal malfunction has occurred in GW-BASIC. Report to your dealer the conditions under which the message appeared.
52
Bad file number
A statement or command references a file with a file number that is not open or is out of range of file numbers specified at initialization.
53
File not found
A LOAD, KILL, NAME, FILES, or OPEN statement references a file that does not exist on the current diskette.
54
Bad file mode
An attempt is made to use PUT, GET, or LOF with a sequential file, to LOAD a random file, or to execute an OPEN with a file mode other thanI, O, A, or R.
55
File already open
A sequential output mode OPEN is issued for a file that is already open, or a KILL is given for a file that is open.
56
Unprintable error
An error message is not available for the error condition which exists. This is usually caused by an error with an undefined error code.
57
Device I/O Error
Usually a disk I/O error, but generalized to include all I/O devices. It is a fatal error; that is, the operating system cannot recover from the error.
58
File already exists
The filename specified in a NAME statement is identical to a filename already in use on the diskette.
59-60
Unprintable error
No error message is available for the existing error condition. This is usually caused by an error with an undefined error code.
61
Disk full
All disk storage space is in use.
62
Input past end
An INPUT statement is executed after all the data in the file has been input, or for a null (empty) file. To avoid this error, use the EOFfunction to detect the end of file.
63
Bad record number
In a PUT or GET statement, the record number is either greater than the maximum allowed (16,777,215) or equal to zero.
64
Bad filename
An illegal form is used for the filename with LOAD, SAVE, KILL, or OPEN; for example, a filename with too many characters.
65
Unprintable error
No error message is available for the existing error condition. This is usually caused by an error with an undefined error code.
66
Direct statement in file
A direct statement is encountered while loading a ASCII-format file. The LOAD is terminated.
67
Too many files
An attempt is made to create a new file (using SAVE or OPEN) when all directory entries are full or the file specifications are invalid.
68
Device Unavailable
An attempt is made to open a file to a nonexistent device. It may be that hardware does not exist to support the device, such as lpt2: or lpt3:, or is disabled by the user. This occurs if an OPEN "COM1: statement is executed but the user disables RS-232 support with the /c: switch directive on the command line.
69
Communication buffer overflow
Occurs when a communications input statement is executed, but the input queue is already full. Use an ON ERROR GOTO statement to retry the input when this condition occurs. Subsequent inputs attempt to clear this fault unless characters continue to be received faster than the program can process them. In this case several options are available:
Increase the size of the COM receive buffer with the /c: switch.
Implement a hand-shaking protocol with the host/satellite (such as: XON/XOFF, as demonstrated in the TTY programming example) to turn transmit off long enough to catch up.
Use a lower baud rate for transmit and receive.
70
Permission Denied
This is one of three hard disk errors returned from the diskette controller.
An attempt has been made to write onto a diskette that is write protected.
Another process has attempted to access a file already in use.
The UNLOCK range specified does not match the preceding LOCK statement.
71
Disk not Ready
Occurs when the diskette drive door is open or a diskette is not in the drive. Use an ON ERROR GOTO statement to recover.
72
Disk media error
Occurs when the diskette controller detects a hardware or media fault. This usually indicates damaged media. Copy any existing files to a new diskette, and reformat the damaged diskette. FORMAT maps the bad tracks in the file allocation table. The remainder of the diskette is now usable.
73
Advanced Feature
An attempt was made to use a reserved word that is not available in this version of GW-BASIC.
74
Rename across disks
Occurs when an attempt is made to rename a file to a new name declared to be on a disk other than the disk specified for the old name. The naming operation is not performed.
75
Path/File Access Error
During an OPEN, MKDIR, CHDIR, or RMDIR operation, MS-DOS is unable to make a correct path-to-filename connection. The operation is not completed.
76
Path not found
During an OPEN, MKDIR, CHDIR, or RMDIR operation, MS-DOS is unable to find the path specified. The operation is not completed.


Wednesday, 10 December 2014

GUESS A NUMBER USING IF_ELSE

GUESS A NUMBER

Now that we know all there is to know about random numbers, it is time to try some in a program. This first program creates a number in the range of 1 to 100. Then you get to guess the number. The computer will provide hints.
10  REM *********************************************************
20  REM *  GUESS1                                              *
30  REM *  Guess a random number selected by a BASIC program    *
40  REM *********************************************************
50  RANDOMIZE TIMER
60  NUMBER% = INT(1 + RND * 100)
70  CLS
80  PRINT "Guess a number in the range 1 and 100"
90  INPUT GUESS%
100 IF GUESS% = NUMBER% THEN GOTO 140
110 IF GUESS% > NUMBER% THEN PRINT "Too High!  Try Again"
120 IF GUESS% < NUMBER% THEN PRINT "Too Low!  Try Again"
130 GOTO 90
140 PRINT "Very Good!  You Guessed the Number."
150 END

ALL Reserved WORDS(CAN't be used as variable name)

         ABS     DATE$   GET
       AND     DEF      GOSUB
       ASC      DEFDBL    GOTO
       ATN      DEFINT         HEX$
       AUTO        DEFSNG            IF
       BEEP         DEFSTR       IMP
       BLOAD         DELETE        INKEY$
       BSAVE                   
       DRAW        INPUT
       CDBL         EDIT       INPUT#
       CHAIN                      ELSE      INPUT$
       CHDIR                      END          INSTR
       CHR$                       ENVIRON      INT
       CINT                       ENVIRON$      INTER$
       CIRCLE                     EOF          IOCTL
       CLEAR                      EQV           IOCTL$
       CLOSE                      ERASE          KEY
       CLS                        ERDEV           KILL
       COLOR                      ERDEV$        LEFT$
       COM                        ERL             LEN
       COMMON                     ERR          LET
       CONT                       ERROR           LINE
       COS                        EXP            LIST
       CSNG                       FIELD         LLIST
       CSRLIN                     FILES      LOAD
       CVD                        FIX            LOC
       CVI                        FNxxxxxxxx     LOCATE
       CVS                        FOR            LOF
       DATA                       FRE              LOG
       LPOS                       POS              STICK
       LPRINT                     PRESET         STOP
       LSET                       PRINT          STR$
       MERGE                      PRINT#         STRIG
       MID$                       PSET            STRING
       MKDIR                      PUT            SWAP
       MKD$                       RANDOMIZE      SYSTEM
       MKI$                       READ           TAB(
       MKS$                       REM            TAN
       MOD                        RENUM           THEN
       MOTOR                      RESET           TIME$
       NAME                       RESTORE       TIMER
       NEW                        RESUME         TO
       NEXT                       RETURN         TROFF
       NOT                        RIGHT$       TRON
       OCT$                       RMDIR     USING
       OFF                        RND          USR
       ON                         RSET        VAL
       OPEN                       RUN            VARPTR
       OPTION                     SAVE      VARPTR$
       OR                         SCREEN      VIEW
       OUT                        SGN             WAIT
       PAINT                      SHELL         WEND
       PEEK                       SIN            WHILE
       PEN                        SOUND         WIDTH
       PLAY                       SPACE$       WINDOW
       PMAP                       SPC(          WRITE
       POINT                      SQR           WRITE#
       POKE                       STEP          XOR

USING MULTIPLE DATA FOR SINGLE READ STATEMENT

The DATA statements can also supply more that one variable with each READ. To do this, separate each piece of data by a comma. The READ must then use more than one variable name. Try this program:
10 FOR X% = 1 TO 3
20   READ FIRST$,SECOND$,THIRD%
30   PRINT FIRST$ SECOND$ THIRD%
40 NEXT X%
50 END
60 DATA Call,me,1
70 DATA Call,me,2
80 DATA Call,me,3
Each piece of data in a DATA statement is called a FIELD. The fields are separated by commas. When they are read, the first field is placed in the first variable name of the READ statement. The second field is placed in the second variable, and so on. The variable type must match the type of data. For example, the integer variable THIRD% in the READ on line 20 can only be used to hold whole numbers. An error message is issued if you try to place letters into an integer variable. This works just like INPUT.
If a field in a DATA statement contains commas, semicolons (;), or many blank spaces, that field must be enclosed in quotation marks.
Each time a READ statement is executed it gathers the input from the next DATA statement. Therefore, one DATA statement must exist for each time READ executes. If a READ is executed after all DATA statements have been processed, BASIC issues the error message Out of Data and the program ends.

Tuesday, 1 July 2014

PROGRAM#9 *TO PRINT A TIME TABLE*



PROGRAM#8 *TO PRINT SUM OF 1-10*


image processing

PROGRAM#7 *PROGRAM TO PRINT EVEN NO.*



PROGRAM#6 *TO FIND LARGEST OF 3 INPUTED VALUES*



PROGRAM#5 *PARK ENTRY FORM WITH RESTRICTIONS*



PROGRAM#4 *PROGRAM OF BUS CHARGE*



PROGRAM#3 *TO CREATE AN ENDLESS LOOP USING GOTO STATEMENT*


PROGRAM#2 *TO ADD, SUBTRACT, MULTIPLY OR DIVIDE NUMBERS*




PROGRAM#1 *CONCATENATION*

concatenation is the process in which the airthmetic plus sign joins with two string to make them count count 1 for example 1+1 = 2 but in string a+a=aa and in string it is called concatination.


CONCATENATION IS A STEP THAT ALLOWS YOU TO ADD TWO OR MORE STRING VALUES TO MAKE IT AS ONE. E.G. "PAK" ;A$ :"IS"; B$: "TAN";C$  .. A$+ B$+C$="PAKISTAN"

Wednesday, 4 June 2014

what do you mean by variable and constants in term of assigning values

1)what is the meaning of variable in urdu?
ans.  badalti huwi   غیرمستقل     

2)what is the meaning of constant in urdu?
ans. مسلسل جاری and unchangeable, na badalnay wali

3)what is variable and constant in terms of programming? 

ans) *******The difference between variables and constants is that variables can change their value at any time but constants can never change their value. (The constants value is lockedfor the duration of the program). Constants can be very useful, Pi for instance is a good example to declare as a constant*******.
***********************************************************************************
*********variable is a quantity that can change while constant is a quantity that cannot change during program execution.
variable is a name given to the memory space in which a a constant is stored

eg. int x =10;
here, x is a variable because later in the program you can write
x= 15;

whereas, 10 is constant because you can never write later in a program that
10=20;  *********************************************************************

***********************************************************************************
Example
Which of the following are variables and which are constants?
  1. The temperature outside your house. This is a variable. The temperature outside your home will change depending on the weather.
  2. The number of square feet in a room that is 12 ft by 12 ft.< This is a constant. The square feet in a room 12 ft by 12 ft is always 144 square feet. It does not change.
  3. The noise level at a concert. This is a variable. The noise level changes depending on the number of people talking and yelling at any given time. *****************************************************************************



Tuesday, 3 June 2014

DAta Types definition and details

Data Types:
A data type in a programming language is a set of data with values having predefined characteristics. Examples of data types are: integer(0-9), floating point unit number(0.0 - 9.0), character(A-Z and a-z), string(combination of alphabets and numbers example address). Usually, a limited number of such data types come built into a language. The language usually specifies the range of values for a given data type, how the values are processed by the computer, and how they are stored.

examples of data types:
integer: your roll number or id card number(123 or 423011234567 etc)
float: population or average count(89.45% or 42,000,11122.34848)
string: flatno123 road abc city country900
character: 'a' or 'z'
 NOTE: character is single alphabet not cluster or combination of alphabets if combination occurs then it will be considered as string.