Word Document Properties



Download 8,82 Mb.
Pdf ko'rish
bet74/207
Sana16.03.2022
Hajmi8,82 Mb.
#496217
1   ...   70   71   72   73   74   75   76   77   ...   207
Bog'liq
VBA For Dummies 5th Ed.pdf ( PDFDrive )

Public
:
Tells VBA that it should allow other program elements to see
the affected elements
Private

Tells VBA that it should hide the affected elements from other
programming elements
75
Chapter 3: Writing Structured VBA Programs
08_046500 ch03.qxp 12/5/06 5:34 PM Page 75


Defining the effects of scope
The best way to learn about scope is to begin working with it. You can experi-
ment with simple uses of scope to see how a change in scope affects your
programs. The most important rule is that scope only affects everything out-
side the current block. That’s right: The Lego example works here, too. (See
the earlier section “Taking the Lego Approach.”)
Making a module private by adding 
Option Private Module
at the begin-
ning of the module means that everything in that module is invisible to the
outside world. Even if the module contains a 
Public Sub
, only the other 
elements inside the module can see it — the 
Public Sub
is invisible to
everything outside the module. Likewise, when you’re declaring a 
Private
Sub
, everything within the current module can still see it, but nothing out-
side the current module can.
Listing 3-4 demonstrates some of the basic elements of scope. Other exam-
ples in the book refine this concept, but this is a good starting point.
Listing 3-4
Using Global Variables
‘ Declare a private global variable.
Private MyGlobalVariable As String
Public Sub GlobalTest()
‘ Set the value of the global variable.
MyGlobalVariable = “Hello”
‘ Display the value.
MsgBox MyGlobalVariable
‘ Call the GlobalTest2 Sub.
GlobalTest2
‘ Display the value on return from the call.
MsgBox MyGlobalVariable
End Sub
Private Sub GlobalTest2()
‘ Show that the global variable is truly global.
MsgBox MyGlobalVariable
‘ Change the value of the global variable.
MyGlobalVariable = “Goodbye”
End Sub
76

Download 8,82 Mb.

Do'stlaringiz bilan baham:
1   ...   70   71   72   73   74   75   76   77   ...   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