Professional Documents
Culture Documents
UNIT 18 p4
UNIT 18 p4
Variables
In any program, the data that is put in must be stored somewhere. Areas called variables are
defined to where the programs store their data. There are two main attributes of variables, one of
which is a name, and this is specified to find the variable inside of the program. The other
attribute is a data type and what this is that whatever variable the data can store; the data type
defines that data.
Loops
In a program if there are instructions that need to be repeated a certain number of times they are
called loops. In VB if there is something that has to be repeated until a certain condition is met
then this is called a Do loop. Conditional loops can have the condition to be placed at the end of
the loop, this is commonly known as post-check. There are many types of loops however there
are only two main ones. These loops are:
Conditional Loops – This executes the loop repeatedly until some condition is met
Fixed Loops A Fixed loop like a said before follows a set of instructions as to how many times the
program should repeat itself. If I set the program to repeat itself 5 times, it will loop itself 5
times. In visual basic these loops are implemented using for statements.
Public class frmLoop
Next
Logical operators
Logical operators are what combine two or more conditions together. The three main operators
are AND, OR and NOT. I will explain them in more detail. AND is what produces the outcome
true if both sides are true. OR is what produces true if both statements are true. NOT is what
produces the opposite result to whatever the outcome is. below are some logic operator :
Operator Use
= Equality
<> Inequality
< Less than
> Greater than
Greater than or
>=
equal to
Less than or equal
<=
to
Input statements
An input statement in VB can be for example If....Else and Select Case statements. If...Else
statements tend to get quite complicated when there are a variety of conditions that need to be
tested. If you would like to use multiple If statements, this is where the Select Case comes in as it
is the other option.
Conditional statements
In VB, conditional statements are used to execute different actions for different decisions. Some
examples of conditional statements in VB include: If statement, If..Then...Else statement and
If....Then...Else If Statement. The If...Then..Else statement is normally used to execute a part of
code if the condition is true. The If..Then..Else If statement is used when there is a large amount
of code that you would like to execute.
Assignment statements
Assignment statements are when values can be assigned to certain variables. Assignment
statements can be used by using mathematical operators such as plus and minus. If
operators are combined with each other then order of execution is based on the actual order of
the mathematical operators.
Output statements
Output statements are completed by using the controls in VB.
Variables
Global variables are approached by any function that is part of the main program. They are put into
play by combining memory locations with the names of the variable. Unlike local variables, global
variables do not come back into play each time the function has been called back. Global variables
are used when you need the value outside of the scope that it was originally created in.