Requirements:
Ability to read the section and key of the INI file to read the corresponding value.
such as a configuration file
SMSVote.ini
---------------------------------
[SMSVote]
Server=(local)
DB=SMSVote
User=sa
PassWord=123
[DB2Vote]
Server=192.168.0.1
DB=DB2
User=sa
PassWord=---------------------------------
Principal Program (method):
Inifile.asp
-----------------------------------------------
<%
Set inifiledictionary = CreateObject ("Scripting.Dictionary")
Sub inifileload (ByVal filspc)
Inifiledictionary.removeall
FILSPC = LCase (FILSPC)
If left (FILSPC, 1) = "P" then
' physical path
Phypth = m ID (FILSPC, InStr (FILSPC, "=") + 1)
Else
' Virtual path
Phypth = Server.MapPath (Mid (FILSPC, InStr (FILSPC, "=") + 1)
End If
Set Filsys = CreateObject ("Scripting.FileSystemObject")
Set inifil = Filsys.opentextfile (phypth, 1
Do While not inifil.atendofstream
Strbuf = inifil.readline
If strbuf <> "then
' There ' are data on This is
if left (strbuf, 1) <> "then
' It ' is not a comment
if left (strbuf, 1) =" [Then
' It ' s a s Ection header
Hdrbuf = Mid (Strbuf, 2, Len (STRBUF)-2)
Else
' It ' s a value
StrPtr = InStr (strbuf, "=")
altbuf = LCase (Hdrbuf & "¦" & Left (Strbuf, StrPtr-1))
did while inifiledictionary.exists (ALTBUF)
Altbuf = Altbuf & "_"
Loop
Inifiledictionary.add altbuf, Mid (Strbuf, StrPtr + 1)
End If
End If
E nd if
loop
Inifil.close
Set inifil = Nothing
Set filsys = no
end Sub
Function Inifilevalue by Val valspc)
Dim ifarray
StrPtr = InStr (VALSPC, "¦")
VALSPC = LCase (VALSPC)
If strptr = 0 Then
' They W Ant the whole section
Strbuf = "
StrPtr = Len (valspc) + 1
valspc = valspc +" ¦ "
Ifarray = inifilediction ary. Keys
For i = 0 to Inifiledictionary.count-1
if left (Ifarray (i), strptr) = VALSPC then
' It ' from the SEC tion
If Strbuf <> "" then
Strbuf = strbuf & "~"
End If
Strbuf = strbuf & Ifarray (i) & "= "& Inifiledictionary (Ifarray (i))
end if
next
else
'They want a specific value
StrBuf = IniFileDictionary(ValSpc)
end if
IniFileValue = StrBuf
End Function
Function Chr(section,key)
char1=IniFileValue(section)
SearchString =char1
SearchChar = key
MyPos=Instr(1,SearchString,SearchChar,1)
'char2=section+key
char1=mid(char1,MyPos+len(key)+1,len(char1)-MyPos+1)
SearchString =char1
SearchChar = "~"
MyPos=Instr(1,SearchString,SearchChar,1)
if MyPos<>0 then
char1=mid(char1,1,MyPos-1)
else
char1=mid(char1,1)
end if
Chr = char1
End Function
%>