Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create a configuration file

Status
Not open for further replies.

PCBrandon

IS-IT--Management
Jan 6, 2007
17
Hello,

I am looking into creating a text file that normal people can read and change the values of in English. Then my ASP can parse the configuration file and apply the settings... Example:


config.txt
Code:
{APPLICATION}
Enabled = True
Name = My App
Access = Everyone

{LAYOUT}
TextColor = White
BackgroundColor = Black

{DATABASE}
Database Type = MSACCESS
Database Name = mydb.mdb
Use Encryption = Yes

ASP would search the text file for a specific field (like Name) and then apply the setting (like printing out "My App" in big bold letters at the top).

Thanks in advance!
 
Your tags need to be case insensitive and would be preferable if it didn't have spaces. If the config file is opened in notepad and the default font is Arial, there isn't a lot of difference between one space and two spaces. The user won't be able to see the difference between

"Use Encryption" and "Use Encryption"

It is better to have camel notation type tags like UseEncryption.

It would be nice to add a leading comment character as well like ! or ' or # so you can have something like

Code:
# Make sure the background is dark
# Note: US spelling of colour
TextColor = White

Easiest way is to create a dictionary, put the tags as the key.
 
So I could create a loop and use the FSO to go through the text file, create an item with the tag in the text file as the key and the response as the value?

Would simply looping through each line of the text file and add any line that doesn't start with a # to the dictionary be a good way of doing this?

Thanks for your help.
 
If you already know how to make a COM object, then make one that uses the Win32API to read/write to an INI file.

Specifically, calls to GetPrivateProfileString and WritePrivateProfileString would allow you to leverage the built-in ability of Windows to parse .INI files.

You could probably even use google to find a set of pre-written freeware functions and then just put a COM wrapper around it so it can be used in ASP.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top