Word Document Properties


Chapter 4: Storing and Modifying Information



Download 8,82 Mb.
Pdf ko'rish
bet104/207
Sana16.03.2022
Hajmi8,82 Mb.
#496217
1   ...   100   101   102   103   104   105   106   107   ...   207
Bog'liq
VBA For Dummies 5th Ed.pdf ( PDFDrive )

Chapter 4: Storing and Modifying Information
09_046500 ch04.qxp 12/5/06 5:54 PM Page 109


110
Part II: Learning the Ropes 
09_046500 ch04.qxp 12/5/06 5:54 PM Page 110


Chapter 5
Creating Structured Programs
In This Chapter
Using the 
If...Then
statement
Using the 
Select Case
statement
Using 
Do
loops
Using 
For Next
loops
Using the 
GoTo
statement
S
tructures
help organize your VBA code so that it can perform more tasks
more efficiently. Special 
statements
can help organize the code so that it
accomplishes tasks based on decisions or performs the same task multiple
times. In this chapter, I demonstrate how to use the special statements used
to make decisions, perform tasks more than once, or redirect control to
another area of the program. The result of using these statements is increased
program structure, which makes controlling program execution easier.
These statements also improve program flexibility. A program that uses the
right statements can perform a wider variety of tasks and take into account
outside conditions, such as the day of the week or the current state of the
computer. Statements that control program flow are essential to writing pro-
grams that need less input from you and perform more tasks automatically.
For example, VBA can help you create Word documents that automatically
reflect special days, such as a business anniversary, or Excel reports where
VBA automatically tracks business quarters.
Exercising Control with Structures
Few programs use all the statements in the program file all the time. You
might want the program to perform one task when you click Yes and another
task when you click No. The statements for both tasks appear in the code,
but the program executes only one set of statements.
10_046500 ch05.qxp 12/5/06 5:35 PM Page 111


To control program execution, the developer adds special statements — such
as the 
If...Then
statement — that show the beginning and end of each task
and also decide which task to execute. You might think that letting the com-
puter decide which task to execute would cause the developer to lose control
of the program. However, the developer hasn’t lost control of the program,
because the decision-making process is predefined as part of the program
design.
Most developers refer to the beginning and ending statements for a task as a
control structure
because the statement combination adds control to a pro-
gram. When you see the 
If...Then
statement with its accompanying 
End
If
statement in code, the two statements combine to form an 
If...Then
structure.
Because the program contains more than one task, it has more than one path
of execution. When you add control structures, the number of execution
paths increases exponentially. For example, a program with one control
structure has two paths of execution, but a program with two control struc-
tures has four paths. As you can imagine, the task of debugging the applica-
tion becomes harder when you add control structures, so designing your
program carefully is important.
You can also 
nest
control structures. A program might require multiple deci-
sion points to address a specific need. For example, the program might need
to decide whether you requested an apple or an orange. When you select an
apple, the program then might have to decide between a yellow, green, or red
apple. The program can’t make the second decision without the first, so the
second decision is nested within the first.
Making a Decision with the
If...Then Statement
Most programs require decision-making code. When you need to make the
same decision every time that you perform a task and the outcome of the
decision is always the same, then making the decision is something that you
can tell VBA to do for you by using the 
If...Then
statement. Decision-
making code has several benefits:

Download 8,82 Mb.

Do'stlaringiz bilan baham:
1   ...   100   101   102   103   104   105   106   107   ...   207




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish