|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
减少客户内IT专业人才缺乏带来的影响。ASP的客户员工利用浏览器进入相关的应用软件,简单易用,无需专业技术支持。选择自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
-----------------------------------------------
<%
setIniFileDictionary=CreateObject("Scripting.Dictionary")
SubIniFileLoad(ByValFilSpc)
IniFileDictionary.RemoveAll
FilSpc=lcase(FilSpc)
ifleft(FilSpc,1)="p"then
Physicalpath
PhyPth=mid(FilSpc,instr(FilSpc,"=")+1)
else
Virtualpath
PhyPth=Server.MapPath(mid(FilSpc,instr(FilSpc,"=")+1))
endif
setFilSys=CreateObject("Scripting.FileSystemObject")
setIniFil=FilSys.OpenTextFile(PhyPth,1)
dowhilenotIniFil.AtEndOfStream
StrBuf=IniFil.ReadLine
ifStrBuf""then
Thereisdataonthisline
ifleft(StrBuf,1)";"then
Itsnotacomment
ifleft(StrBuf,1)="["then
Itsasectionheader
HdrBuf=mid(StrBuf,2,len(StrBuf)-2)
else
Itsavalue
StrPtr=instr(StrBuf,"=")
AltBuf=lcase(HdrBuf&"|"&left(StrBuf,StrPtr-1))
dowhileIniFileDictionary.Exists(AltBuf)
AltBuf=AltBuf&"_"
loop
IniFileDictionary.AddAltBuf,mid(StrBuf,StrPtr+1)
endif
endif
endif
loop
IniFil.Close
setIniFil=nothing
setFilSys=nothing
EndSub
FunctionIniFileValue(ByValValSpc)
dimifarray
StrPtr=instr(ValSpc,"|")
ValSpc=lcase(ValSpc)
ifStrPtr=0then
Theywantthewholesection
StrBuf=""
StrPtr=len(ValSpc)+1
ValSpc=ValSpc+"|"
ifarray=IniFileDictionary.Keys
fori=0toIniFileDictionary.Count-1
ifleft(ifarray(i),StrPtr)=ValSpcthen
Thisisfromthesection
ifStrBuf""then
StrBuf=StrBuf&"~"
endif
StrBuf=StrBuf&ifarray(i)&"="&IniFileDictionary(ifarray(i))
endif
next
else
Theywantaspecificvalue
StrBuf=IniFileDictionary(ValSpc)
endif
IniFileValue=StrBuf
EndFunction
FunctionChr(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)
ifMyPos0then
char1=mid(char1,1,MyPos-1)
else
char1=mid(char1,1)
endif
Chr=char1
EndFunction
%>
怎样利用?
看看这个:
conn.asp
-----------------------------------------------
<!--#includefile="inifile.asp"-->
<%
onerrorresumenext
dimconn,connstr,dbuid,dbpwd,dbname,dbip
callIniFileLoad("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"
setconn=Server.CreateObject("adodb.Connection")
connstr="PROVIDER=SQLOLEDB;DATASOURCE="&dbip&";UID="&dbuid&";PWD="&dbpwd&";DATABASE="&dbname
conn.openconnstr
response.writeconn
response.writeerr.description
%>
想法是和程序员的想法不一样的.至于为什么.大家去想一想.跟心理学有关的 |
|