Open这个Ini, 以每次读取一行的方式读取到: strReadDo While Not FEof(1) ... if Instr(strRead,"[SetTime]")>0 then blnFound=true exit do endif Loop if blnFound then '存在 else '不存在 endif
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。
...
if Instr(strRead,"[SetTime]")>0 then
blnFound=true
exit do
endif
Loop
if blnFound then
'存在
else
'不存在
endif
附:一个要是vbNullString,而不能是"",什么原因,你可查一下MSDN。