Data Types, Operators, and Control Structures in Programming

Data in Programming: Constants and Variables

Data can behave in two different ways in a program:

  • Constants: Their value never changes during the execution of the program.
  • Variables: Their value varies as often as necessary.

Naming Conventions

When naming a variable or constant, keep in mind:

  • You can use any alphanumeric character, but it must always begin with a letter.
  • Spaces are not allowed; use the underscore character for compound names (e.g., my_variable).
  • Name length may not exceed 32 characters.
  • Do not use dots or other special characters, nor language keywords (e.g., text, caption).

Basic Data Types

  • String: Textual data.
  • Integer: Whole numbers.
  • Long Integer: Larger whole numbers.
  • Decimal: Single-precision floating-point numbers.
  • Double: Double-precision floating-point numbers.
  • Date and Time: Represents dates and times.
  • Date: Represents dates.

Variable declaration is typically done using a keyword like dim. If you declare a variable without defining the type, the program automatically assigns the type variant.

The print function displays literal texts and the values of variables.

The value of a constant cannot be modified during the execution of the program.

Data Type Characters

  • String: $
  • Integer: %
  • Long Integer: &
  • Decimal: !

Arithmetic Operators

OperatorSymbolDescription
Sum+Calculates the sum of two or more variables.
Difference-Calculates the difference between two values.
Multiplication*Multiplies the value of the variables.
Division/Calculates the value of the division of two numerical values.
Exponentiation^Calculates the value of a variable raised to the power of another.
Quotient of Division/Calculates the quotient of the division of two numerical values.
Remainder of DivisionmodCalculates the remainder of the division between two values.

Scope of Variables

ScopeLocationDescription
ProcedureAt the beginning of the procedureVariables are available only within the procedure.
FormIn the general declarations section of the formVariables may be used in all procedures within the form.
ApplicationIn the general declarations section of the form, using public instead of dimVariables declared as public may be used in any form of the application, but their location must be specified when used.

Control Structures

  • Sequential Structures: Allow the execution of the program to be conducted in a specific order. Statements are written sequentially, one after another, in the order they should be interpreted.
  • Selective Structures: Used to make logical decisions. Also known as alternative or decision structures. A condition is evaluated, and depending on its outcome, one or another action is performed.
  • Repetitive Structures: Also called loops, these structures repeat a sequence of statements a specified number of times.

Iteration: Execution of all actions or instructions that form a loop.

If Statement

Evaluates a condition and, if met, executes a series of specific instructions. Otherwise, the program will continue with other alternative instructions.

Logical Operators

OperatorSymbolDescription
ANDandRequires all conditions in the expression to be true for the expression to be true. If any condition is false, the expression is false.
ORorThe expression is true if at least one of the conditions is true. The expression is false only if none of the conditions are met.
NOTnotThe expression is true when the condition is false, and false when the condition is true.