如何检测INI文件中某个Section是否存在?

海搜科技 2004-11-05 03:26:19
如何检测INI文件中某个Section是否存在?
设FA.ini已存在
如何检测Section(如:SetTime)是否已写到INI文件中。
...全文
952 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
king 2020 2005-03-04
  • 打赏
  • 举报
回复
这个老帖可以写清楚点吗?不懂
homezj 2004-11-05
  • 打赏
  • 举报
回复
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。
a达哥a 2004-11-05
  • 打赏
  • 举报
回复
Open这个Ini, 以每次读取一行的方式读取到: strRead

Do While Not FEof(1)
...
if Instr(strRead,"[SetTime]")>0 then
blnFound=true
exit do
endif
Loop
if blnFound then
'存在
else
'不存在
endif

1,217

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧