create performance logs when you suspect that your program doesn’t work
as fast as it could.
Program data storage should appear in a format that’s convenient for you
because you’re the only one who will see it. You should try to store the
information by using the program itself. This is relatively easy to do with a
program such as Word or Excel.
In some cases, you might want to go to the
extra trouble of creating the document by using indirect programming of
another application. See Chapter 16 for details on this technique. Finally, you
can use an informational Event Log entry to store the information.
When no other technique will work (or other techniques are just too inconve-
nient), you can always rely on a simple text file to
store the program informa-
tion. The problem with using text files for complex data is that you can’t
format them, and they can’t contain information in easy-to-use formats, such
as graphs. The best reason to use a text file is that it’s an easy and conve-
nient method for storing text information.
Working with Settings
Many
applications, including Windows, use INI files to store information. The
INI file has a standard format that is easy to work with. View any of the INI
files in the Windows folder, such as
Win.INI
or
System.INI
, and you see
two kinds of entry.
The first is the section entry, which is surrounded by square
brackets, such as the
[fonts]
section in the
Win.INI
file.
The second kind of
entry is a key-and-value pair. The key comes first and is separated from the
value by an equals sign.
You might need to create an INI file for your program. The INI file provides
the means for storing settings and restoring them later. The
Dictionary
object provides the perfect means for working with INI settings because it
uses a key-and-value pair for storing information.
The example in this section
shows how to read and write an INI file.
Writing an INI file
It pays to create one
Dictionary
object for each section of your INI file.
Using the objects in this way makes it easy to quickly locate the information
that you need. The trade-off is that you
have more objects to work with, and
your program will experience a small performance hit. Listing 10-1 contains
the code that you need to use a
Dictionary
object to write to an INI file.
(You can find the source code for this example on the Dummies.com site at
http://www.dummies.com/go/vbafd5e
.)
232
Do'stlaringiz bilan baham: