例如:
[aaa]
id=1
x=0
y=1
z=2
id=2
x=4
y=3
z=
id=3
x=3
y=2
z=5
在VB6.0中读写配置文件(.ini)的时候,重名怎么实现,给个可行的方法,最好不用再借助其他的配置文件或数据库

解决方案 »

  1.   

    [aaa]
    Count=3
    [1]  
    x=0 
    y=1 
    z=2 
    [2] 
    x=4 
    y=3 
    z= 
    [3]
    x=3 
    y=2 
    z=5 
    '建议写成这样的格式.getiniStr "aaa" ,"Count"for i=1 to count
       getinistr i ,"X"
       getinistr i ,"Y"
       getinistr i ,"Z"
    next
      

  2.   


    Option ExplicitPrivate Declare Function GetPrivateProfileSection Lib "KERNEL32" Alias "GetPrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As LongPublic Function GetInfoSection(strSection As String, strIniFile 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(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 FunctionPrivate Sub Command1_Click()
      Dim i As Long
      Dim A() As String
      A = GetInfoSection("aaa", "c:\1.ini") 'C:\1.ini 改为你的文件名
      For i = 1 To UBound(A)
        MsgBox A(i)
      Next
    End Sub
      

  3.   

    格式如你所述,不会轻易更改,则可采用不要当作ini文件来读,将读取的操作封装在一个类中,以免对将来变更带来更大影响。一行一行读取,包含字符“[aaa]”开始一个循环(读取id,读取x、y、z),空行结束。
    一行中根据“=”位置直接提取出id、x、y、z的值。
      

  4.   

    哪应该不是标准的ini文件,就按普通的文本文件读然后自己解析吧
      

  5.   

    我上学时写的读写INI文件的模块代码,直接保存成一个.bas文件,然后把里面的变量换成你需要的就可以了。
    更多例程http://download.csdn.net/user/mokton
    Private 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
    'GetPrivateProfileString(Section , KeyWord , 读取失败的代替值 ,KeyWordValue返回值 , Value值缓冲区大小 , INI路径)
    Private Declare Function WritePrivateProfileString Lib "Kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lplFileName As String) As Long
    'WritePrivateProfileString(Section , KeyWord ,KeyWordValue ,INI路径)Public IniPath As String
    Public netName As String
    Public TimeInterval As String
    Public sEnableVerb As String
    Public sDisableVerb As StringPublic Function Loadings() As Boolean
        On Error GoTo EE
        IniPath = App.Path + "\Net.ini"
        netName = GetFromINI("NetConfig", "ConName", IniPath)
        TimeInterval = GetFromINI("NetConfig", "TimeInterval", IniPath)
        sEnableVerb = GetFromINI("NetConfig", "Enable", IniPath)
        sDisableVerb = GetFromINI("NetConfig", "Disable", IniPath)
        If netName = "" Then GoTo EE
        Loadings = True
        Exit Function
    EE:
        Loadings = False
    End FunctionPrivate Function GetFromINI(AppName As String, KeyName As String, FileName As String) As String
       Dim RetStr As String
       Dim Result As Long
       RetStr = String(255, Chr$(0))
       Result = GetPrivateProfileString(AppName, ByVal KeyName, "", RetStr, Len(RetStr), FileName)
       RetStr = TrimNull(RetStr)
       GetFromINI = RetStr
    End FunctionPrivate Function TrimNull(Item As String) As String
        Dim pos As Integer
        pos = InStr(Item, Chr$(0))
        If pos Then Item = Left$(Item, pos - 1)
        TrimNull = Item
    End Function
      

  6.   

    ini文件里 不可能在同一个标签里有相同的项的   你就当一般文件操作     不要按ini 处理     
    SupermanKing 发表于:2008-08-24 17:02:327楼 得分:0 
    说白了就是字符串处理,还要“绝顶高手请进...”, 
    都不知道你是想讽刺帮你答题的人还是赞扬帮你答题的人。