Access VBA Macro Programming

(Joao Candeias) #1

Chapter 4 Programming Basics: Decisions and Looping.


Chapter 4 Programming Basics: Decisions and Looping.


W


hen writing programs, it’s important to understand how programs make
decisions and perform looping. Looping is the process of carrying out the
same set of instructions until certain conditions are met.
I’m sure you’re familiar with decisions. After all, you have to make them every day. For
example when you wake up, which shirt do you decide to put on? You make this decision
based on various facts such as what the weather is like outside and what you are doing today.
Your life would be very dull if you never had to make any decisions—think what it would be
like if it was already decided what shirt you wore each day!
Programs also have to make decisions based on the parameters to which they have access.
The computer program would also be very dull if it never made a decision. For example, if a
program tries to load a text file and the file is not found, a decision needs to be made as to
what to do next. Should the program simply display an error message and crash, or should it
show some intelligence and alert the user that the file is missing and offer an alternative action?
Artificial intelligence is something that is frequently discussed in computing circles. By
having your programs make decisions, you are introducing some primitive intelligence into
your program. Admittedly, it is your intelligence that goes into the code, but it tells the program
what to do in the event of different circumstances happening. You are effectively writing a set
of rules to deal with various situations.
Looping is also something everyone does daily without thinking about it. When you eat a
meal, you perform the same routine of taking food from a plate and putting it into your mouth.
Computer programs frequently loop around the same piece of code a number of times until a
certain condition is met.


35

Free download pdf