Word Document Properties


Chapter 5: Creating Structured Programs



Download 8,82 Mb.
Pdf ko'rish
bet114/207
Sana16.03.2022
Hajmi8,82 Mb.
#496217
1   ...   110   111   112   113   114   115   116   117   ...   207
Bog'liq
VBA For Dummies 5th Ed.pdf ( PDFDrive )

Chapter 5: Creating Structured Programs
10_046500 ch05.qxp 12/5/06 5:35 PM Page 125


Notice how the code uses a 
Select Case
statement to choose between
word choices. This 
Select Case
statement also lacks a 
Case Else
clause
because it doesn’t rely on user input. This is one example where the 
Case
Else
clause can’t contribute anything to error trapping or default process-
ing. This example also introduces techniques for modifying the font charac-
teristics of text in a document.
The next two lines of code are especially important. First, the code updates
CurrentWord
. You must do this, or else the loop will continue forever
because 
CurrentWord
is always less than 
TotalWords
. Not updating the
CurrentWord
value results in an endless loop — a common source of bugs
in programming code. The second statement moves the selection to the next
word in the document by using the updated 
CurrentWord
value. Note the
order of the statements. You must update 
CurrentWord
first and then move
to the next word in the text. Figure 5-3 shows the document used to test this
program with the interesting formatting in place.
Using the Do...Loop While statement
The 
Do...Loop While
statement works the same as the 
Do While...Loop
statement. The difference is that this statement always executes once because
the expression used to verify a need to loop appears at the end of the struc-
ture. Even if the expression is false, this statement still executes at least one
time. You can use this statement when you want to ensure that a task is
always completed at least one time.
Using the Do Until...Loop statement
The 
Do Until...Loop
statement continues processing information until
the expression is false. You can view the 
Do While...Loop
statement as a
loop that continues while a task is incomplete. The 
Do Until...Loop
state-
ment continues until the task is finished. The subtle difference between the
two statements points out something interesting: They rely on your perspec-
tive of the task to complete. These two statement types are completely inter-
changeable. The big difference is how you define the expression used to
signal the end of the looping sequence.
Using the Do...Loop Until statement
The 
Do...Loop Until
statement is the counterpart of the 
Do
Until...Loop
statement. This statement examines the expression at the
end of the loop, so it always executes at least once even if the expression is
false.
126

Download 8,82 Mb.

Do'stlaringiz bilan baham:
1   ...   110   111   112   113   114   115   116   117   ...   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