You are on page 1of 3

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:

Fixed loops - which execute a fixed number of times

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

PrivateSub CmdFor Click (ByValsenderAsSystemObjext,ByVale e As systemEventArgs


Handles CmdFor.Click
Dim A As Integer
A=1
For 1 = 1 To 5
MsgBox(A)

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 Purpose Example

And Returns True when Expr1 And Expr2


Expr1 and Expr2
are true.

Or Returns True when Expr1 Or Expr2


either Expr1 or
Expr2 is true.
Not Returns True when Not Expr
Expr is not true.

Operator Use
= Equality
<> Inequality
< Less than
> Greater than
Greater than or
>=
equal to
Less than or equal
<=
to

Input statements
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.

Dim UCASPass As Integer 'Stores the number of Passes'


Dim UCASMerit As Integer 'Stores the number of Merits'
Dim UCASDestinction As Integer 'Stores the number of Distinctions'

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. Below is the code example from my program:

Public Class FrmSelection

Private Sub TmrRun_Tick(ByVal sender As System.Object, ByVal e As


System.EventArgs)

End Sub

This code show a conditional statement as it basically says that if you click the “Option one” hcekc
box the progress bar will go forward by 1 and if you click the “option two” check box the bar will go
back by 1.This known as a Conditional statement.

Assignment statements:
Assignment statements is 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.
below table show a list of possible mathematical operator:
Operator Meaning Examples Order of
precedence
^ Exponentiation 2^3=8 1
(raise to the
power of)
* Multiplication 3*2=6 2
/ Integer Division 5/2=2 3
Mod Remainder Part 5 mod 2 = 1 4
of division
+ Add 4+5=9 5
- Subtract

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.

You might also like