登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

凌晨阳光

 
 
 

日志

 
 

INI文件读取操作  

2016-09-19 11:58:24|  分类: 默认分类 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
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

Declare Function GetPrivateProfileSectionNamesA Lib "kernel32.dll" (ByVal szValue$, ByVal nSize&, ByVal szFileName$) As Long

Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, _
                                                                                            lpKeyName As Any, ByVal lpDefault As String, _
                                                                                            ByVal lpRetunedString As String, _
                                                                                            ByVal nSize As Long, ByVal lpFileName As String) As Long
Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" _
   (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, _
   ByVal lpFileName As String) As Long


'*************************************************************************
'读取INI中所有Section名
'*************************************************************************
Function GetSectionsName(sPath) As String()
    Dim szBuffer$, nLen%
    Dim strTmp     As String
    Dim sArray()     As String
    Dim i       As Integer
    Dim nStart     As Integer
    Dim nEnd       As Integer
    
    szBuffer = String(1024, 0)
    Call GetPrivateProfileSectionNamesA(szBuffer, 1024, sPath)
    
    strTmp = szBuffer
    i = 1
    Do While strTmp <> ""
        nStart = nEnd + 1
        nEnd = InStr(nStart, szBuffer, vbNullChar)
        strTmp = Mid$(szBuffer, nStart, nEnd - nStart)
        If Len(strTmp) > 0 Then
            ReDim Preserve sArray(1 To i)
            sArray(i) = strTmp
            i = i + 1
        End If
    Loop
    GetSectionsName = sArray
End Function

'读取Section中的所有Item名
Function GetIniItems(sSection As String, FileName As String) As String()
    Dim strReturn     As String * 32767
    Dim strTmp     As String
    Dim nStart     As Integer
    Dim nEnd       As Integer
    Dim i       As Integer
    Dim sArray()     As String
       
    Call GetPrivateProfileSection(sSection, strReturn, Len(strReturn), FileName)
       
    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
    
    GetIniItems = sArray
End Function

'读取Item的值
Function GetIniItemKey(sSectionName As String, KeyName As String, FileName As String) As String
   Dim RetStr As String
   RetStr = String(10000, Chr(0))
   GetIniItemKey = Left(RetStr, GetPrivateProfileString(sSectionName, ByVal KeyName, "", RetStr, Len(RetStr), FileName))
End Function

'写入INI
WritePrivateProfileString “Section”,"Item","Keys","Path"

'删除Section
WritePrivateProfileString Section, vbNullString, vbNullString, FileName

‘删除Item
WritePrivateProfileString Section, KeyName, vbNullString, FileName
  评论这张
 
阅读(240)| 评论(0)

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018