六月婷婷综合激情-六月婷婷综合-六月婷婷在线观看-六月婷婷在线-亚洲黄色在线网站-亚洲黄色在线观看网站

明輝手游網中心:是一個免費提供流行視頻軟件教程、在線學習分享的學習平臺!

用ASP讀INI設置文件的函數

[摘要]選擇自 mind_1220 的 Blog 要求: 能夠讀取按照 INI文件的Section和Key來讀出相應的Value。 比如一個配置文件 SMSVote.ini --------------------------------- [SMSVote] Server=(local...

選擇自 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 
                   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 
               'This  is  from  the  section 
               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 
%> 
 
如何使用? 
 
看看這個: 
conn.asp 
----------------------------------------------- 
<!--#include  file="inifile.asp"-->   
 
<% 
         on  error  resume  next 
         dim  conn,connstr,dbuid,dbpwd,dbname,dbip 
         call  IniFileLoad("virtual=SMSVote.ini")  '配置文件的名字 
         dbuid=Chr("SMSVote","User")            'Section="SMSVote",Key="User" 
         dbpwd=Chr("SMSVote","PassWord")    'Section="SMSVote",Key="PassWord" 
         dbname=Chr("SMSVote","DB")              'Section="SMSVote",Key="DB" 
         dbip=Chr("SMSVote","server")          'Section="SMSVote",Key="server" 
 
set  conn=Server.CreateObject("adodb.Connection") 
connstr="PROVIDER=SQLOLEDB;DATA  SOURCE="&dbip&";UID="&dbuid&";PWD="&dbpwd&";DATABASE="&dbname 
conn.open  connstr 
'response.write  conn 
response.write  err.description 
%> 




主站蜘蛛池模板: 婷婷综合在线观看丁香 | 性视频亚洲 | 青娱乐在线免费观看 | 小黄鸭b站视频 | 天天爱天天色天天干 | 性刺激性色爽爱小说 | 日韩中文字幕视频 | 日本高清高色 | 一区二区视频在线播放 | 欧美亚洲免费 | 日本一区二区三区在线 观看网站 | 全部免费毛片 | 日韩一级片在线播放 | 婷婷丁香五月中文字幕 | 青青青青操 | 中文国产成人精品久久96 | 伊人快播| 五月天婷婷在线视频 | 日本黄色app | 七七七久久久久人综合 | 日本色综合网 | 日韩亚射 | 欧美呦呦在线 | 天天天天天天干 | 欧美性猛交xxxx乱大交蜜桃 | 无码精品日韩中文字幕 | 日韩成人毛片高清视频免费看 | 亚洲精品综合在线 | 欧美透逼视频 | 伊人影院网 | 日日夜夜网| 日本精品在线观看 | 午夜在线播放视频在线观看视频 | 日本高清无卡码一区二区久久 | 三级黄色片在线观看 | 日韩中文字幕在线 | 日日噜噜噜噜人人爽亚洲精品 | 午夜久久久精品 | 日本一区二区三区免费高清在线 | 亚洲综合久久成人69 | 亚洲欧美日韩在线2020 |