function | Function 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 = Mid (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 as not Inifil.atendofstream
Strbuf = Inifil.readline
If Strbuf <> "" Then
' There is Data '
If left (Strbuf, 1) <> ";" Then
' It ' s not a comment
If left (strbuf, 1) = "[" Then
' It ' s a section header
Hdrbuf = Mid (Strbuf, 2, Len (STRBUF)-2)
Else
' It ' s a value
StrPtr = InStr (strbuf, "=")
Altbuf = LCase (Hdrbuf & "¦" & Left (Strbuf, StrPtr-1))
Do While inifiledictionary.exists (ALTBUF)
Altbuf = Altbuf & "_"
Loop
Inifiledictionary.add Altbuf, Mid (Strbuf, StrPtr + 1)
End If
End If
End If
Loop
Inifil.close
Set Inifil = Nothing
Set Filsys = Nothing
End Sub
Function Inifilevalue (ByVal valspc)
Dim Ifarray
StrPtr = InStr (VALSPC, "¦")
VALSPC = LCase (VALSPC)
If StrPtr = 0 Then
' They want the whole section
Strbuf = ""
StrPtr = Len (VALSPC) + 1
VALSPC = valspc + "¦"
Ifarray = Inifiledictionary.keys
For i = 0 to Inifiledictionary.count-1
If left (Ifarray (i), strptr) = VALSPC Then
' Thi