如何检测INI文件中某个Section是否存在?
设FA.ini已存在
如何检测Section(如:SetTime)是否已写到INI文件中。

解决方案 »

  1.   

    Open这个Ini, 以每次读取一行的方式读取到: strReadDo While Not FEof(1)
       ...
       if Instr(strRead,"[SetTime]")>0 then
           blnFound=true
           exit do
       endif
    Loop
    if blnFound then
        '存在
    else
       '不存在
    endif
      

  2.   

    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注意第二个参数为Section下的KeyName,若将vbNullString传给它,将返回一个Section下的全部KeyName,每个KeyName用Chr(0)分隔,明白了吧?若返回值为空,则说明该Section下没有Key同理,若将vbNullString传给第一个参数,将返回所有Section名,你的Section在不在,这里就能查到。
    附:一个要是vbNullString,而不能是"",什么原因,你可查一下MSDN。