国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

VB幾個有用的函數

2024-07-21 02:21:01
字體:
來源:轉載
供稿:網友
注釋:————————(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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 甘泉县| 北辰区| 汤原县| 台江县| 民县| 甘谷县| 达孜县| 涟水县| 新野县| 梓潼县| 简阳市| 墨玉县| 河池市| 锡林浩特市| 泸定县| 西昌市| 民县| 固原市| 青冈县| 新龙县| 唐山市| 民县| 新安县| 从江县| 仁寿县| 左贡县| 玛纳斯县| 景宁| 班戈县| 湘潭市| 祁东县| 霍林郭勒市| 邵东县| 永和县| 耒阳市| 德阳市| 普安县| 洪雅县| 中方县| 伊金霍洛旗| 崇仁县|