http://www.daima.com.cn/Info/1/Info892/
来自上边连接'――――――――(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: ype.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
这里的vbNullChar没有定义就可以使用?这里它表示什么意思啊?

解决方案 »

  1.   

    没代表任何东西。ASCII码值为0
      

  2.   

    INI文件读取网上有现成的模块,放到工程里就行了,这么累干什么!
      

  3.   

    Option Explicit
    Private 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
    Private Declare Function WritePrivateProfileString Lib "Kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationname As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long'保持属性值的局部变量
    Private mvarFileName As String '局部复制
    '保持属性值的局部变量
    Private mvarSection As String '局部复制
    Public Property Let Section(ByVal vData As String)
    '向属性指派值时使用,位于赋值语句的左边。
    'Syntax: X.Section = 5
        mvarSection = vData
    End Property
    Public Property Get Section() As String
    '检索属性值时使用,位于赋值语句的右边。
    'Syntax: Debug.Print X.Section
        Section = mvarSection
    End PropertyPublic Property Let FileName(ByVal vData As String)
    '向属性指派值时使用,位于赋值语句的左边。
    'Syntax: X.FileName = 5
        mvarFileName = vData
    End PropertyPublic Property Get FileName() As String
    Attribute FileName.VB_UserMemId = 0
    '检索属性值时使用,位于赋值语句的右边。
    'Syntax: Debug.Print X.FileName
        FileName = mvarFileName
    End Property
    Public Function ReadValue(ByVal Key As String, Optional DefValue As String, Optional mSection As String) As String
    Dim RetVal As String, Worked As IntegerRetVal = String$(255, 0)
    mvarSection = IIf(mSection = vbNullString, mvarSection, mSection)
    Worked = GetPrivateProfileString(mvarSection, Key, "", RetVal, Len(RetVal), mvarFileName)
    If Worked = 0 Then
        ReadValue = DefValue
    Else
        ReadValue = Left(RetVal, InStr(RetVal, Chr(0)) - 1)
    End If
    End FunctionPublic Sub WriteValue(ByVal Key As String, ByVal KeyValue As String, Optional mSection As String)
    mvarSection = IIf(mSection = vbNullString, mvarSection, mSection)
    WritePrivateProfileString mvarSection, Key, KeyValue, mvarFileName
    End Sub