当前位置: 首页 > 图文教程 > 网络编程 > ASP > 用ASP读INI配置文件的函数

ASP
一种比较方便的ASP分页程序
用一套论坛程序架设多个论坛
ASP与ASP.NET在COOKIE方面的区别
较长数据无法在Asp页面中取出的三种解决方法
初试WAP之wml+ASP查询
动态网站首页的静态生成方法
使用正则表达式实现模式图片新闻.ASP
让你的WAP网站有更好的兼容性
WAP版的手机号码所在地查询
asp模仿 Lotus Notes 的界面程序
ORACLE920与ASP的连接问题的解决办法
利用SQLSERVER存储过程实现ASP用户身份验证
在ASP中自动创建多级文件夹的函数(使用FSO)
利用instr()函数防止SQL注入攻击
利用XSL和ASP实现XML文档在线编辑
表单对象textarea内容的格式控制(回车、换行、空格)
针对select写了一个通用的option输出函数
ASP无组件BMP汉字生成类+汉字点阵库
时间、空间性能极优的asp无组件上传类
无组件生成BMP验证码

用ASP读INI配置文件的函数


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 29 ::
收藏到网摘: n/a

 

选择自 mind_1220 的 Blog

要求: 
能够读取按照  INI文件的Section和Key来读出相应的Value。 
比如一个配置文件   
SMSVote.ini 
--------------------------------- 
[SMSVote] 
Server=(local) 
DB=SMSVote 
User=sa 
PassWord=123 
[DB2Vote] 
Server=192.168.0.1 
DB=DB2 
User=sa 
PassWord= 
--------------------------------- 
 
 
主体程序(方法)  : 
 
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  while  not  IniFil.AtEndOfStream 
       StrBuf  =  IniFil.ReadLine 
       if  StrBuf  <>  ""  then 
           'There  is  data  on  this  line 
           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 
                   IniF