Home | Advertising Info92 USERS CURRENTLY ONLINE   
PowerASP
   Site Search Contact Us Monday, September 25, 2017  


How to make a custom configuration file to use with your ASP scripts.




NOTICE:
Tim recently made an Optimized GetConfig Routine which is more efficient but more complicated.

GetConfig Function
This function was designed by my Co-worker Tim Lasek.
It allows you to make a config file and read values from it easily.
This is a pretty neat little function.

Function GetConfig(Email)

Usage:    cfg_FontFace = GetConfig("config.txt", "cfg_FontFace")

Result:    Arial, Helvetica

Below is the Function Source Code, Example Config File, and Example Usage Code

<%
Function GetConfig(FileName, VarName)
Delimiter = "=="
Dim fs, a
Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.OpenTextFile(Server.MapPath(FileName))
lFound = False
While (a.AtEndOfStream = False) And (lFound = False)
lVar = a.ReadLine
If (lVar <> "") And (InStr(1, lVar, Delimiter) <> 0) Then
tArry = Split(lVar, Delimiter)
name = Trim(tArry(0))
value = Trim(tArry(1))
If LCase(VarName) = LCase(name) Then
lFound = True
lVar = value
End If
End If
Wend
If lFound = False Then lVar = ""
a.Close
GetConfig = lVar
End Function
%>

<%
cfg_FontFace = GetConfig("config.txt", "cfg_FontFace")
cfg_FontColor = GetConfig("config.txt", "cfg_FontColor")
cfg_BorderSize = GetConfig("config.txt", "cfg_BorderSize")
cfg_TableSpacing = GetConfig("config.txt", "cfg_TableSpacing")
cfg_TablePadding = GetConfig("config.txt", "cfg_TablePadding")
cfg_SomeText = GetConfig("config.txt", "cfg_SomeText")
%>

<%= cfg_FontFace %><br>
<%= cfg_FontColor %><br>
<%= cfg_BorderSize %><br>
<%= cfg_TableSpacing %><br>
<%= cfg_TablePadding %><br>
<%= cfg_SomeText %><br>

Would result in the following output.

Arial, Helvetica
#000000
0
1
3
Jack and Jill... went up the hill!


However, you would probably use the variables for other than just displaying them on the page. This is just an example of how to use the function.

The config file in this example looks like this.

All variables are to be declared on a single line.
All variables declared using format: [var name] [delimiter] [value].
All lines that don't contain the delimiter are ignored as comments.


cfg_FontFace == Arial, Helvetica
cfg_FontColor == #000000
cfg_BorderSize == 0
cfg_TableSpacing == 1
cfg_TablePadding == 3
cfg_SomeText == Jack and Jill... went up the hill!

Download the example config file.
config.txt

Also if running this on NT make sure the anonymous webserver account has read permissions on this text file. Most likely it probably will have this by default.

   Active Server Pages Rule The World
Contact Us  
All artwork, design & content contained in this site are Copyright 1998 - 2017 PowerASP.com and Christopher J. Williams
Banner ads ,other site logos, etc are copyright of their respective companies.
STATS Unless otherwise noted - All Rights Reserved.

Active Server Pages asp source code database MS SQL MS Access .mdb adovbs.inc cookies calendar codes sql commands scripts asp programming tutorials iis web server components CJWSoft ASPProtect ASPBanner ASPClassifieds www.aspclassifieds.com, www.powerasp.com,www.cjwsoft.com,www.aspphotogallery.com,www.codewanker.com,www.aspprotect.com,www.aspbanner.com