Word Document Properties


Chapter 4: Storing and Modifying Information



Download 8,82 Mb.
Pdf ko'rish
bet93/207
Sana16.03.2022
Hajmi8,82 Mb.
#496217
1   ...   89   90   91   92   93   94   95   96   ...   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 97


Using Boolean values to make decisions
The 
Boolean
type is the easiest to use and understand. This type is used to
indicate yes or no, true or false, and on or off. You can use this type to work
with any two-state information. It’s commonly used to represent data values
that are diametrically opposed. Chapter 5 shows how to use 
Boolean
values
to make decisions. Listing 4-10 shows several conversion techniques that you
can use with 
Boolean
values.
Listing 4-10
Making Decisions with Boolean Values
Public Sub BooleanCheck()
‘ Create a Boolean data type.
Dim MyBool As Boolean
‘ Set MyBool to True
MyBool = True
‘ Display the native value.
MsgBox “MyBool = “ + CStr(MyBool), _
vbOKOnly, _
“Native Value”
‘ Display the numeric value.
MsgBox “MyBool = “ + CStr(CInt(MyBool)), _
vbOKOnly, _
“Numeric Value”
‘ Make MyBool equal to a number. Only the number
‘ 0 is False; everything else is True.
MyBool = CBool(0)
MsgBox “MyBool = “ + CStr(MyBool), _
vbOKOnly, _
“Converted Numeric Value”
End Sub
The code begins by declaring a 
Boolean
variable and setting its value. As with
numeric variables, you can assign a 
Boolean
variable directly to a string as
long as that’s the only thing that you do. When working in a mixed data type
environment, such as the one shown in the code, you must use the appropri-
ate function (such as 
CStr
) to perform the conversion.
The 
Boolean
type isn’t numeric — it’s logical . . . simply a decision value.
You can convert it to a number, as shown in the example code. The value is
always 
-1
for 
True
values and 
0
for 
False
values.
VBA also lets you convert a numeric value to a 
Boolean
type by using the
CBool
function shown in the code. Any value that you store in the 
Boolean
,
other than 
0
, equates to 
True
. Converting the 
Boolean
back to a number
still shows 
-1
for 
True
values and 
0
for 
False
.
98

Download 8,82 Mb.

Do'stlaringiz bilan baham:
1   ...   89   90   91   92   93   94   95   96   ...   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