注释:————————(1)————————————
注释:获得指定ini文件中某个节下面的所有键值 truezq,,需要下面的api声明
注释:private declare function getprivateprofilesection lib "kernel32" alias "getprivateprofilesectiona" (byval lpappname as string, byval lpreturnedstring as string, byval nsize as long, byval lpfilename as string) as long
注释:返回一个字符串数组
注释:调用举例:
注释:dim arrclass() as string
注释:arrclass = getinfosection("class", "d:/type.ini")
public function getinfosection(strsection as string, strinifile as string) as string()
dim strreturn as string * 32767
dim strtmp as string
dim nstart as integer, nend as integer, i as integer
dim sarray() as string
call getprivateprofilesection(strsection, strreturn, len(strreturn), strinifile)
strtmp = strreturn
i = 1
do while strtmp <> ""
nstart = nend + 1
nend = instr(nstart, strreturn, vbnullchar)
strtmp = mid$(strreturn, nstart, nend - nstart)
if len(strtmp) > 0 then
redim preserve sarray(1 to i)
sarray(i) = strtmp
i = i + 1
end if
loop
getinfosection = sarray
end function
注释:————————(2)————————————
注释:作用:去掉字符串中的首尾空格、所有无效字符
注释:测试用例
注释:dim strres as string
注释:dim strsour as string
注释:
注释:strsour = " " & vbnullchar & vbnullchar & " ab cd" & vbnullchar
注释:strres = zqtrim(strsour)
注释:msgbox " 长度=" & len(strsour) & "值=111" & strres & "222"
public function zqtrim(byval strsour as string) as string
dim strtmp as string
dim nlen as integer
dim i as integer, j as integer
dim strnow as string, strvalid() as string, strnew as string
注释:strnow 当前字符
注释:strvalid 有效字符
注释:strnew 最后生成的新字符
strtmp = trim$(strsour)
nlen = len(strtmp)
if nlen < 1 then
zqtrim = ""
exit function
end if
j = 0
for i = 1 to nlen
strnow = mid(strtmp, i, 1) 注释:每次读取一个字符
注释:msgbox asc(strnow)
if strnow <> vbnullchar and asc(strnow) <> 9 then 注释:如果有效,则存入有效数组
redim preserve strvalid(j)
strvalid(j) = strnow
j = j + 1
end if
next i
strnew = join(strvalid, "") 注释:将所有有效字符连接起来
zqtrim = trim$(strnew) 注释:去掉字符串中的首尾空格
end function
注释:————————(3)————————————
注释:检查文件是否存在,存在返回 true,否则返回false
public function checkfileexist(strfile as string) as boolean
if dir(strfile, vbdirectory) <> "" then
checkfileexist = true
else
checkfileexist = false
end if
end function
注释:————————(4)————————————
注释:获得指定ini文件中某个节下面某个子键的键值,需要下面的api声明
注释:public declare function getprivateprofilestring lib "kernel32" alias _
注释: "getprivateprofilestringa" (byval lpapplicationname as string, _
注释: byval lpkeyname as any, byval lpdefault as string, byval lpreturnedstring _
注释: as string, byval nsize as long, byval lpfilename as string) as long
注释:返回一个字符串
注释:调用举例:
注释:dim strrun as string
注释:strrun = getinivalue("windows","run", "c:/windows/win.ini")
public function getinivalue(byval lpkeyname as string, byval strname as string, byval strinifile as string) as string
dim strtmp as string * 255
call getprivateprofilestring(lpkeyname, strname, "", _
strtmp, len(strtmp), strinifile)
getinivalue = left$(strtmp, instr(strtmp, vbnullchar) - 1)
end function
注释:————————(5)————————————
注释:获得windows目录 ,需要下面的api声明
注释:private declare function getwindowsdirectory lib "kernel32" alias "getwindowsdirectorya" (byval lpbuffer as string, byval nsize as long) as long
注释:返回一个字符串,如“c:/windows”、“c:/winnt”
注释:调用举例:
注释:dim strwindir as string
注释:strwindir = getwindir()
private function getwindir()
dim windir as string * 100
call getwindowsdirectory(windir, 100)
getwindir = left$(windir, instr(windir, vbnullchar) - 1)
end function
注释:————————(6)————————————
注释:获得windows系统目录,需要下面的api声明
注释:private declare function getsystemdirectory lib "kernel32" alias "getsystemdirectorya" (byval lpbuffer as string, byval nsize as long) as long
注释:返回一个字符串,如“c:/windows/system”、“c:/winnt/system32”
注释:调用举例:
注释:dim strsysdir as string
注释:strsysdir = getsystemdir()
private function getsystemdir()
dim strsysdir as string * 100
call getsystemdirectory(strsysdir, 100)
getsystemdir = left$(strsysdir, instr(strsysdir, vbnullchar) - 1)
end function