Word Document Properties


Part III: Expanding Your VBA Horizons



Download 8,82 Mb.
Pdf ko'rish
bet196/207
Sana16.03.2022
Hajmi8,82 Mb.
#496217
1   ...   192   193   194   195   196   197   198   199   ...   207
Bog'liq
VBA For Dummies 5th Ed.pdf ( PDFDrive )

Part III: Expanding Your VBA Horizons 
16_046500 ch10.qxp 12/5/06 5:36 PM Page 236


data to read. Each iteration of the loop selects an action based on the content
of 
DataElement
.
Notice the 
Set Selector = AppConfig
statement. This statement does
more than you might think. It actually makes 
Selector
and 
AppConfig
equal so that any changes made to 
Selector
also appear in 
AppConfig
.
This technique provides a generic reference when parsing the key/value pairs
in the file. The routine doesn’t have to do anything special because the cor-
rect 
Dictionary
object is already selected.
The final piece of coding to consider is the key/value pair parsing. The INI 
file stores them as two strings separated by an equals sign. The information
appears on a single line. Using the string manipulation functions shown 
separates the two values so that the code can add them to the appropriate
dictionary.
Now it’s time to discuss the 
OpenReadConfig
function. As with 
OpenWrite
Config
, this is a generic function for working with files. Listing 10-4 shows
how this function looks.
Listing 10-4
Opening a Configuration File for Reading
Public Function OpenReadConfig(AppName As String, Filename
As String, ByRef Output As TextStream) As
Boolean
‘ Define the path variable.
Dim DataPath As String
DataPath = Application.UserLibraryPath + AppName + “\”
‘ Create a file system object.
Dim FS As FileSystemObject
Set FS = New FileSystemObject
‘ Determine whether the file exists.
If Not FS.FileExists(DataPath + Filename) Then
‘ Tell the user there are no config settings.
OpenReadConfig = False
‘ Exit the Sub without reading the file.
Exit Function
End If
‘ Create a text file object.
Set Output = FS.OpenTextFile( _
DataPath + Filename, ForReading)
(continued)
237

Download 8,82 Mb.

Do'stlaringiz bilan baham:
1   ...   192   193   194   195   196   197   198   199   ...   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