例如:我想要在ini的配置文件中按一定规律动态加上项目如下:[Item]
001 = 1111
002 = 2222
003 = 3333以此类推**写入的问题:
但其中的 001,002,003等是在程序里可以有个地方输入的,也就是可以新增的(类似数据库的一个表)但我想通过配置文件来实现,如何写出这样的代码?**读出的问题:
如何根据这样的一个001,002,003,(到最后)有规律的项目,如何使用一个类似***数组***的变量里???

解决方案 »

  1.   

    此API函数是读INI文件的
    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
    这个是往里写的API
    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 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 Sub Form_Load()
        Dim Ret As String, NC As Long
        'Write the setting to the file (c:\test.ini) under
        '   Project1 -> Keyname
        WritePrivateProfileString App.Title, "KeyName", "This is the value", "c:\test.ini"
        'Create a buffer
        Ret = String(255, 0)
        'Retrieve the string
        NC = GetPrivateProfileString(App.Title, "KeyName", "Default", Ret, 255, "C:\test.ini")
        'NC is the number of characters copied to the buffer
        If NC <> 0 Then Ret = Left$(Ret, NC)
        'Show our string
        MsgBox Ret
        'Delete the file
        Kill "c:\test.ini"
    End Sub
      

  2.   

    加上一个cnt字段记录咯
    [ini]
    cnt = 2
    001=...
    002=...
      

  3.   

    用FORMAT将自然数转化成字符串再保存嘛
      

  4.   

    正确。
    使用API函数,当写入项目不存在时,会自动添加该项目,所以不用担心。
      

  5.   

    [initial]
    num=4[Option]
    tmp_0=001
    tmp_1=002
    tmp_2=003
    tmp_3=004先设置一个范围值然后再根据所设定的规则来添加option里的项目