幸运飞艇投注平台app
全國服務熱線:0597-2297794 24小時咨詢:15080281944 15080287989
設為首頁加入收藏聯系我們

VB下幾個有用的函數

來源:互聯網   發布時間:2013/12/27 21:55:44     閱讀數:668

'————————(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 * 32767Dim strTmp As StringDim nStart As Integer, nEnd As Integer, i As IntegerDim sArray() As String     Call GetPrivateProfileSection(strSection, strReturn, Len(strReturn), strIniFile)    strTmp = strReturni = 1Do While strTmp <> ""nStart = nEnd + 1nEnd = InStr(nStart, strReturn, vbNullChar)strTmp = Mid$(strReturn, nStart, nEnd - nStart)If Len(strTmp) > 0 ThenReDim Preserve sArray(1 To i)sArray(i) = strTmpi = i + 1End If    LoopGetInfoSection = sArrayEnd 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 StringDim strTmp As StringDim nLen As IntegerDim i As Integer, j As IntegerDim strNow As String, strValid() As String, strNew As String'strNow 當前字符'strValid 有效字符'strNew 最后生成的新字符    strTmp = Trim$(strSour)nLen = Len(strTmp)If nLen < 1 ThenzqTrim = ""Exit FunctionEnd Ifj = 0For i = 1 To nLenstrNow = Mid(strTmp, i, 1) '每次讀取一個字符'MsgBox Asc(strNow)If strNow <> vbNullChar And Asc(strNow) <> 9 Then '如果有效,則存入有效數組ReDim Preserve strValid(j)strValid(j) = strNowj = j + 1End If    Next i    strNew = Join(strValid, "") '將所有有效字符連接起來zqTrim = Trim$(strNew) '去掉字符串中的首尾空格End Function'————————(3)————————————'檢查文件是否存在,存在返回 TRUE,否則返回FALSEPublic Function CheckFileExist(strFile As String) As Boolean    If Dir(strFile, vbDirectory) <> "" ThenCheckFileExist = TrueElseCheckFileExist = FalseEnd IfEnd 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 StringDim 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 * 100Call 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 * 100Call GetSystemDirectory(strSysDir, 100)GetSystemDir = Left$(strSysDir, InStr(strSysDir, vbNullChar) - 1)  End Function

 如果您覺得此文對您有啟發或者幫助,可以花3秒鐘收藏到QQ空間。平時注意多收集,用時不會干著急!

[您可能感興趣的文章]
最新案例
網站建設資訊
  1. [資訊]Google Adsense ?
  2. [資訊]如何防止google adse?
  3. [資訊]使你的網站更專業--談網站優化?
  4. [資訊]優化你的站點,讓它加載的再快一?
  5. [資訊]網站建設:提高網站訪問量的策略?
  6. [資訊]揭開虛擬主機供應商的面紗?
SEO常見問題解答
  1. [SEO]什么是ALT屬性?
  2. [SEO]什么是鏈接錨文本?
  3. [SEO]什么是動態頁面?
  4. [SEO]HTTP狀態碼是什么意思??
  5. [SEO]鏈接養殖場?
  6. [SEO]首選域?
點擊立刻咨詢
幸运飞艇投注平台app 大乐透选号什么叫胆 福建时时彩11选五投注 宁夏11选5开奖结果走势图 cba联赛青岛注册名单 重庆时时彩官方网站 福彩双色球预测 晓游棋牌大厅3d下载 体彩排列五大奖新闻 体彩p5出号走势图带连线 ewin棋牌娱乐