VB简单的INI文件读取
- 时间:2015年04月02日 15:24:31 来源:魔法猪系统重装大师官网 人气:14020
VB简单的INI文件读取
新建一个模块,将下面的代码粘进去
Public 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
Public 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文件中的数据
Dim ret As Long
Dim buff As String
buff = String(255, 0)
ret = GetPrivateProfileString(section, name, value, buff, 256, "INI文件路径")
Text1.Text = buff
[section]
name=value
需要注意的是代码中的value
并不是输出的值,而是当读取的值为空时显示的东西