利用ASP读取INI的文件 INI的文件如下:
[哈哈123]
Server=111111
[2哈3哈4]
Server=22222
DB=33333
具体ASP要求:
1.读取所有INI的节名([]里的)下Server 和 DB名 全部都列表出来 每50个一页 可以翻页
2.输入框写入一个 然后搜索披对节名是否有这个 有的话就显示出该节名Server 和 DB名
3.以上两个例子都同有一个功能下拉框选择INI文本
4.第一个例子需要按数字大小排列,比如第一个例子是按Server 或者 DB排列 从数字大排列到小
例如:
第一个的要求例子:
用户名 地址 要求
哈哈123 111111
2哈3哈4 22222 33333
...
...
...
...
第一页 上一页 下一页 最后一页
第二个要求的例子:
请输入用户名: 确定
用户名: *****
地址: *****
要求: ******
第三个要求的例子:
请选择INI文本 (123.ini,456.ini,789.ini)
选择后查询该ini里的内容
------解决方案--------------------
- VB code
smsvote.ini --------------------------------- [smsvote] server=(local) db=smsvote user=sa password=123 [db2vote] server=192.168.0.1 db=db2 user=sa password= <% 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 its not a comment if left(strbuf, 1) = "[" then its a section header hdrbuf = mid(strbuf, 2, len(strbuf) - 2) else its 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 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" %>