Word Document Properties


Chapter 10: Working with Disk Files



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

Chapter 10: Working with Disk Files
16_046500 ch10.qxp 12/5/06 5:36 PM Page 233


It’s important to provide a section header for each of your 
Dictionary
objects, or else you can’t parse the file later. The code writes this heading
first, and then it writes the individual key/value pairs by using a 
For
Each...Next
statement. You can create a single routine to perform this
task, but using the technique shown in the code is actually easier to under-
stand and is self-documenting to a point. As always, make sure that you close
the configuration file before you exit the sub-procedure.
It’s time to look at the 
OpenWriteConfig
sub-procedure in a little more
detail. Listing 10-2 shows this code.
Listing 10-2
Opening a Configuration File for Writing
Public Sub OpenWriteConfig( _
AppName As String, _
Filename As String, _
ByRef Output As TextStream)
‘ Define the path variable.
Dim DataPath As String
‘ Create a path string for the file. Start with the
‘ default program settings path. Add a special folder
‘ for this program.
DataPath = Application.UserLibraryPath + AppName + “\”
‘ Create a file system object.
Dim FS As FileSystemObject
Set FS = New FileSystemObject
‘ Verify the path exists.
If Not FS.FolderExists(DataPath) Then
‘ If not, create it.
FS.CreateFolder DataPath
End If
‘ Create a text file object.
Set Output = FS.CreateTextFile(DataPath + Filename)
End Sub
The code begins by determining the location of the user folder. It then adds
the application name to the path to locate the folder for this application. You
can use this same code no matter what user setting file you open. Creating a
connection to other common folder types follows a similar pattern.
At this point, you need to create a 
FileSystemObject
and use it to deter-
mine whether the application folder exists. If the folder doesn’t exist, you
must create it before you can write data to it. The example uses the
FS.CreateFolder
method to create the new folder.
234

Download 8,82 Mb.

Do'stlaringiz bilan baham:
1   ...   189   190   191   192   193   194   195   196   ...   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