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
RETURN statement is encountered for which there is no previous GOSUB statement.
4
Out of DATA
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$INPOUTWAITPEEKPOKETABSPCSTRING$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 GOTOGOSUBIF-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
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
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
WHILE statement does not have a matching WEND.
30
WEND without WHILE
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
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
LOADKILLNAMEFILES, or OPEN statement references a file that does not exist on the current diskette.
54
Bad file mode
An attempt is made to use PUTGET, or LOF with a sequential file, to LOAD a random file, or to execute an OPEN with a file mode other thanIOA, 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 LOADSAVEKILL, 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 OPENMKDIRCHDIR, 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 OPENMKDIRCHDIR, or RMDIR operation, MS-DOS is unable to find the path specified. The operation is not completed.