VB6.0实现读写配置文件(*.ini文件)

前端之家收集整理的这篇文章主要介绍了VB6.0实现读写配置文件(*.ini文件)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

VB6.0实现读写配置文件(*.ini文件)

2013-11-08 HydroLIB 文章来源
'声明:
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
Declare Function WritePrivateProfileStrin g Lib "kernel32" Alias "WritePrivateProfileStrin gA" (ByVal lpApplicationName As String,ByVal lpString As Any,ByVal lpFileName As String) As Long
Declare Function GetPrivateProfileInt Lib "kernel32" Alias "GetPrivateProfileIntA" (ByVal lpApplicationName As String,ByVal lpKeyName As String,ByVal nDefault As Long,ByVal lpFileName As String) As Long
'读写例子:
Sub RWConfigFile()
'读字符串
Dim lng As Long
Dim retstr As String
retstr = String(260,0)
lng = GetPrivateProfileString("config","para1","",retstr,256,"c:\config.ini")
retstr = Replace(retstr,Chr(0),"")

'读整数
lng = GetPrivateProfileInt("config","para2","c:\config.ini")

'写字符串
lng = WritePrivateProfileStrin g("config","para3","写文件测试","c:\config.ini")
End Sub
config.ini配置文件格式:
[config]
para1=你好abc111
para2=123
para3=写文件测试
特别提示
声明在模块内,配置文件中值两边的空格会被忽略掉。“para1=你好abc111” 和 “para1= 你好abc111 效果相同。
如果文件没有全路径,而是只写文件名config.ini,则读写路径为%windir%\config.ini。

说明:上面的文章虽然是转载来的,不过我测试后读写字符串没问题但读整数部分不正确,希望能对才学VB6.0的朋友们有所帮助

原文链接:https://www.f2er.com/vb/256847.html

猜你在找的VB相关文章