例如
xx INI档内容如下[6]
资料笔数=9
致能=,yes,,,,,,,
[3]
资料笔数=9
致能=,,yes,yes,,,,,
[-1]
资料笔数=9
致能=,,yes,yes,,,,,
[-2]
资料笔数=9
致能=,,yes,yes,,,,,[问题]==================有 "现成" 的 函数 或 API 可以知道(a) 项目总数 = 4
(b) 项目 = [6],[3],[-1],[-2]吗 ?

解决方案 »

  1.   

    http://blog.donews.com/conanlee/archive/2006/03/30/803500.aspx
      

  2.   


    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 LongFunction GetProString(段 As String, 标题 As String, 默认值 As String, 文件名 As String) As String
        Const ProStringLen = 8096
        Dim Res As Long, S As String, i As Long
        S = Space(ProStringLen)
        Res = GetPrivateProfileString(段, 标题, 默认值, S, ProStringLen, 文件名)
        S = Trim(Left(S, Res))
        If S <> "" Then
            i = Len(S)
            Do While Mid(S, i, 1) = vbNullChar
                i = i - 1
            Loop
            S = Left(S, i)
        End If
        GetProString = Trim(S)
    End FunctionPrivate Sub Form_Load()
        Dim Apps() As String, i As Integer
        Apps = Split(GetProString(vbNullString, vbNullString, "", "c:\xx.ini"), vbNullChar)
        Debug.Print "项目总数=" & UBound(Apps) - LBound(Apps) + 1
        For i = LBound(Apps) To UBound(Apps)
            Debug.Print "第" & i; "项 = " & Apps(i)
        Next i
        End
    End Sub
      

  3.   

    土法炼钢-自己写一个函数
    Private Function iniFilter()
     Open App.Path & "\" & "xx.ini" For Input As #1
      b = ""
       Do Until EOF(1)
        Line Input #1, nextline
         b = b & nextline
          Loop
    Close #1strFile = ""
    pstring1 = "["
      pString2 = "]"
      pStart = InStr(b, pstring1)
      If pStart <> 0 Then
      pstop = InStr(pStart, b, pString2)
      End If
      Do While pStart <> 0
      strFileName = Mid(b, pStart, pstop - pStart + 1)
       strFile = strFile & strFileName & ","
       
       i = i + 1
      pStart = InStr(pstop, b, pstring1)
       If pStart = 0 Then
          Exit Do
             End If
      pstop = InStr(pStart, b, pString2, 1)
       Loop
        
        strFile = Left(strFile, Len(strFile) - 1)
       MsgBox "项目总数 = " & i
      MsgBox "项目 =" & strFile
     
    End FunctionPrivate Sub Form_Load()
    iniFilter
    End Sub