Wolf's ASP Toolbox--read the INI config file function with ASP.

Source: Internet
Author: User
Tags config ini
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



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.