Summary Notes - Modular Code
Summary Notes - Modular Code
Modular Code
Modular code is code that uses procedures and functions.
Sub Program Function
A section of code that performs a specific task. A section of code that returns a value.
Example Example
Parameters
Parameters are variables that are passed in and out of sub programs and functions. We pass parameters using two different methods
Arrays are always passed by reference. This is because if we passed arrays by value the program would create a second copy. Arrays are often
large data structures so this is
Inefficient use of processor time to make the second copy
Inefficient use of RAM to store the second copy
LENGTH Returns the length of a LEN(“Jessica”) returns 7 Returns the number of characters the
string string
Checks if the number of characters in
If LEN(ID) <> 5 ID IS NOT equal to 5
Mid$(“computer, 4, 3) returns
put
ASC ASCII Asc(“A”) returns 65 Returns the ASCII value of a A-Z (upper case)
character ASCII values
CHARACTER CHR Chr(97) returns a Takes an ASCII value and returns between 65 and 90
the corresponding character
a – z(lower case)
ASCII values
between 97 and
122
INTEGER INT INT(3.7556) returns 3 Returns the whole number part
of a real number
CONVERSION CINT CINT(3.7556) returns 4 Rounds a real number to the
INTEGER nearest integer
MODULUS MOD First MOD second Returns the remainder of first
divided by second
7 MOD 3 returns 1