网页功能: 加入收藏 设为首页 网站搜索  
读写INI文件的四个函数
发表日期:2006-08-23作者:[转贴] 出处:  

'文件名SourceDB.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

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

 

'以下两个函数,读/写ini文件,固定节点setting,in_key为写入/读取的主键

'仅仅针对是非值

'Y:yes,N:no,E:error

Public Function GetIniTF(ByVal In_Key As String) As Boolean

On Error GoTo GetIniTFErr

GetIniTF = True

Dim GetStr As String

GetStr = VBA.String(128, 0)

GetPrivateProfileString "Setting", In_Key, "", GetStr, 256, App.Path & "\SourceDB.ini"

GetStr = VBA.Replace(GetStr, VBA.Chr(0), "")

If GetStr = "1" Then

GetIniTF = True

GetStr = ""

Else

GoTo GetIniTFErr

End If

Exit Function

GetIniTFErr:

Err.Clear

GetIniTF = False

GetStr = ""

End Function

 

Public Function WriteIniTF(ByVal In_Key As String, ByVal In_Data As Boolean) As Boolean

On Error GoTo WriteIniTFErr

WriteIniTF = True

If In_Data = True Then

WritePrivateProfileString "Setting", In_Key, "1", App.Path & "\SourceDB.ini"

Else

WritePrivateProfileString "Setting", In_Key, "0", App.Path & "\SourceDB.ini"

End If

Exit Function

WriteIniTFErr:

Err.Clear

WriteIniTF = False

End Function


'以下两个函数,读/写ini文件,不固定节点,in_key为写入/读取的主键
'针对字符串值

'空值表示出错

Public Function GetIniStr(ByVal AppName As String, ByVal In_Key As String) As String

On Error GoTo GetIniStrErr

If VBA.Trim(In_Key) = "" Then

GoTo GetIniStrErr

End If

Dim GetStr As String

GetStr = VBA.String(128, 0)

GetPrivateProfileString AppName, In_Key, "", GetStr, 256, App.Path & "\SourceDB.ini"

GetStr = VBA.Replace(GetStr, VBA.Chr(0), "")

If GetStr = "" Then

GoTo GetIniStrErr

Else

GetIniStr = GetStr

GetStr = ""

End If

Exit Function

GetIniStrErr:

Err.Clear

GetIniStr = ""

GetStr = ""

End Function

 

Public Function WriteIniStr(ByVal AppName As String, ByVal In_Key As String, ByVal In_Data As String) As Boolean

On Error GoTo WriteIniStrErr

WriteIniStr = True

If VBA.Trim(In_Data) = "" Or VBA.Trim(In_Key) = "" Or VBA.Trim(AppName) = "" Then

GoTo WriteIniStrErr

Else

WritePrivateProfileString AppName, In_Key, In_Data, App.Path & "\SourceDB.ini"

End If

Exit Function

WriteIniStrErr:

Err.Clear

WriteIniStr = False

End Function

 

我来说两句】 【加入收藏】 【返加顶部】 【打印本页】 【关闭窗口
中搜索 读写INI文件的四个函数
本类热点文章
  揭穿号称内存占用极低的软件的诡计
  用VB6实现真正实用的多线程处理
  读写INI文件的四个函数
  shell函数能以同步方式打开一个exe文件
  VB的API编程精粹
  TAPI笔记
  锁定计算机
  在VB中使用API函数
  巧用API函数增强VB位操作功能
  关机消息的拦截
  让你的文本框“聪明”一点
  在WIN2000下实现程序的关机
最新分类信息我要发布 


三晋宝铺*山西特产专..


山西特产*平遥牛肉*..
  有坑求萝卜!!!求各路精英萝卜!!!
  专业开发直销软件,最火爆3M,互助抢红..
  2015 IEEE先进信息技术、电子与自动化控..
  1比1比例完全仿微信app项目源码转让出售
  西部数码空天猫酷豆旗舰店为您提供一流..
  TerraExplorer Pro 6.5.0
  ProFILE.Master.2000.CAM-DUCT.v2.26.0..
  【上海欣旋】PMP6月考前人广培训班,通..
最新招聘信息

关于我们 / 合作推广 / 给我留言 / 版权举报 / 意见建议 / 广告投放  
Copyright ©2003-2017 Lihuasoft.net webmaster(at)lihuasoft.net
网站编程QQ群   京ICP备05001064号 页面生成时间:0.37067